-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPP0142.cpp
More file actions
43 lines (39 loc) · 755 Bytes
/
CPP0142.cpp
File metadata and controls
43 lines (39 loc) · 755 Bytes
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
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10000001
#define ll long long
using namespace std;
bool nt(int n) {
if (n < 2)
return 0;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return 0;
}
return 1;
}
int euler(ll n) {
ll ans = n;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
ans = ans - ans / i;
while (n % i == 0) {
n /= i;
}
}
}
if (n > 1) {
ans = ans - ans / n;
}
return ans;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << nt(euler(n)) << endl;
}
return 0;
}