-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimeFactors_UVA583.cpp
76 lines (65 loc) · 1.35 KB
/
primeFactors_UVA583.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("primeFactors_UVA583.in");
ofstream fout("primeFactors_UVA583.out");
int main()
{
while (true)
{
bool first = true;
long long n = 0;
fin >> n;
if (n == 0) break;
fout << n << " = ";
if (n < 0)
{
fout << "-1";
n *= -1;
first = false;
}
for (long long i = 2; i * i <= n; i += 2)
{
while (n % i == 0)
{
if (first == true)
{
first = false;
}
else
{
fout << " x ";
}
fout << i;
n /= i;
}
if (i == 2)
{
i = 1;
}
}
if (n > 1)
{
if (first == true)
{
first = false;
}
else
{
fout << " x ";
}
fout << n;
}
fout << '\n';
}
return 0;
}