-
Notifications
You must be signed in to change notification settings - Fork 1
/
ETF.cpp
36 lines (30 loc) · 786 Bytes
/
ETF.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
#include <bitset>
#include <cstdio>
#define MAXN 3000000
using namespace std;
int phi[MAXN + 1], prime[MAXN / 10], sz;
bitset <MAXN + 1> mark;
int main() {
for (int i = 2; i <= MAXN; i++) {
if (!mark[i]) {
phi[i] = i - 1;
prime[sz++] = i;
}
for (int j = 0; j < sz && prime[j] * i <= MAXN; j++) {
mark[prime[j] * i] = 1;
if(i % prime[j] == 0){
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
}
int t, n;
scanf("%d", &t);
for(int i = 0; i < t; i++) {
scanf("%d", &n);
if (n == 1) printf("%d\n", 1);
else printf("%d\n", phi[n]);
}
return 0;
}