-
Notifications
You must be signed in to change notification settings - Fork 2
/
10179.cpp
83 lines (58 loc) · 986 Bytes
/
10179.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
77
78
79
80
81
82
83
#include<stdio.h>
#include<math.h>
char a[32009];
int store[700],m;
int p[6000];
int prime_table() {
int i,j, k = 0;
for(i = 2; i <32000; i ++) a[i] = 1;
for(i = 2; i <= sqrt(32000); ) {
for(j = i+i; j <32000; j += i)
a[j] = 0;
for(i ++; !a[i]; i ++);
}
for(i = 2; i <32000; i ++)
if(a[i])
p[k++] = i;
return 0;
}
int prime_fact(int n) {
int i,limit;
m = 0;
limit = sqrt(n);
for(i = 0; p[i] <=limit; i ++) {
if(n % p[i] == 0 ) {
store[m++] = p[i];
while( n % p[i] == 0) {
n = n / p[i];
if( n == 1)
break;
}
}
if(n == 1)
break;
}
if( n != 1)
store[m ++] = n;
return 0;
}
int result(int n) {
int i,j;
double frc,in;
frc = n;
for(i = 0; i<m; i ++) {
in = store[i];
frc = frc * ( 1 - 1 / in);
}
printf("%.0lf\n",frc);
return 0;
}
int main() {
int n;
prime_table();
while(scanf("%d",&n) && n) {
prime_fact(n);
result(n);
}
return 0;
}