-
Notifications
You must be signed in to change notification settings - Fork 0
/
p583.cpp
57 lines (54 loc) · 1.13 KB
/
p583.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
#include <iostream>
#include <cstdio>
using namespace std;
int flag1, flag2, flag3;
void CommonFactors(long long int x) {
long long int i;
while(x%2==0) {
if(flag1==1) {
printf(" x ");
}
printf("2");
x/=2;
flag1 = 1;
flag2 = 1;
flag3 = 1;
}
for(i=3; i*i<=x; i+=2) {
while(x%i==0) {
if(flag2==1) {
printf(" x ");
}
printf("%lld", i);
x/=i;
flag2 = 1;
flag3 = 1;
}
}
if(x>2) {
if(flag3==1) {
printf(" x ");
}
printf("%lld", x);
}
printf("\n");
}
int main()
{
long long int x;
while(scanf("%lld", &x)==1 && x!=0) {
flag1 = flag2 = flag3 = 0;
if(x<0) {
printf("%lld = -1 x ", x);
CommonFactors(-1*x);
flag1 = 1;
flag2 = 1;
flag3 = 1;
}else {
printf("%lld = ", x);
CommonFactors(x);
flag1 = 1;
flag2 = 1;
}
}
}