-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathETF_totient.cpp
More file actions
46 lines (40 loc) · 1.31 KB
/
ETF_totient.cpp
File metadata and controls
46 lines (40 loc) · 1.31 KB
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
#include<stdio.h>
int at[1000000]={0};
int cntr=2;
int main(){
int t;
scanf("%d",&t);
int n;
while(t--){
scanf("%d",&n);
if(n<3){printf("1\n");continue;}
if(n<5){printf("2\n");continue;}
if(at[n]!=0){printf("%d\n",at[n]);continue;}
int a[n+1];
for(int i=2;i<=n;i++)a[i]=0;
for(int i=cntr;i<=n;i++){
at[i]=i;
}
for(int i=2;i<=n;){
if(a[i]>0){
if(i%6==1)i+=4;
else if(i%6==5)i+=2;
else i++;
continue;
}
for(int j=i;j<=n;j+=i){
a[j]=i;
at[j]=(at[j]*(i-1))/i;
}
if(i%6==1)i+=4;
else if(i%6==5)i+=2;
else i++;
}
if(at[n]==n)
printf("%d\n",at[n]-1);
else
printf("%d\n",at[n]);
if(n>cntr)n=cntr;
}
return 0;
}