forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10392.cpp
65 lines (60 loc) · 777 Bytes
/
10392.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
#include <bits/stdc++.h>
using namespace std;
#define maxn 10000000
typedef long long sss;
char sv[maxn + 2];
int P[664579 + 2], tp;
void Prime_table()
{
int i, j;
for (i = 2; i * i < maxn;)
{
for (j = i + i; j < maxn; j += i)
{
sv[j] = 1;
}
for (i++; sv[i]; i++)
;
}
P[0] = 2;
tp = 1;
for (i = 3; i < maxn; i += 2)
if (!sv[i])
{
P[tp++] = i;
}
}
void Factor(sss N)
{
int i, j;
for (i = 0; i < tp && P[i] * P[i] <= N; i++)
{
if (N % P[i] == 0)
{
while (N % P[i] == 0)
{
printf(" %d\n", P[i]);
N /= P[i];
}
}
if (N == 1)
{
return;
}
}
if (N > 1)
{
printf(" %lld\n", N);
}
}
int main()
{
sss n;
Prime_table();
while (scanf("%lld", &n) && n >= 0)
{
Factor(n);
printf("\n");
}
return 0;
}