-
Notifications
You must be signed in to change notification settings - Fork 0
/
10299.cpp
48 lines (41 loc) · 1.15 KB
/
10299.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
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
int main(void)
{
bool is_prime;
unsigned long target, count;
std::vector<unsigned long> prime = {2, 3, 5, 7, 11, 13};
std::vector<unsigned long> square = {4, 9, 25, 49, 121, 169};
for (int i = 17; i < 31624; i += 2) {
is_prime = true;
for (int j = 0; is_prime && square[j] <= i; ++j) {
is_prime = i % prime[j] != 0;
}
if (is_prime) {
prime.push_back(i);
square.push_back(i * i);
}
}
while (1) {
std::cin >> target;
if (!target) break;
if (target == 1) {
std::cout << "0" << std::endl;
continue;
}
count = target;
for (int i = 0; i < square.size() && square[i] <= target; ++i) {
if (target % prime[i] == 0) {
count -= count / prime[i];
do {
target /= prime[i];
} while (target % prime[i] == 0);
}
}
if (target > 1) count -= count / target;
std::cout << count << std::endl;
}
return 0;
}