标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8976 Accepted Submission(s):
4736
传送门
1 #include<iostream> 2 using namespace std; 3 const int maxn=32790; 4 int euler[maxn+2]; 5 void make() 6 { 7 euler[1]=0; 8 for(int i=2;i<=maxn;++i) 9 euler[i]=i; 10 for(int i=2;i<=maxn;++i) 11 if(euler[i]==i) 12 for(int j=i;j<=maxn;j+=i) 13 euler[j]=euler[j]/i*(i-1); 14 } 15 int main() 16 { 17 make(); 18 int n,t,sum; 19 cin>>t; 20 while(t--) 21 { 22 cin>>n; 23 cout<<euler[n]<<endl; 24 } 25 return 0; 26 }
另一种方法:
1 #include <stdio.h> 2 int gcd(int x,int y) 3 { 4 if(y==0) 5 return x; 6 else 7 return gcd(y,x%y); 8 } 9 int main() 10 { 11 int N; 12 scanf("%d",&N); 13 while(N--) 14 { 15 int a[32800]={0}; 16 int i,j,num; 17 int flag=0; 18 scanf("%d",&num); 19 for(i=2;i<num;i++) 20 { 21 if(num%i==0) 22 { 23 for(j=i;j<num;j+=i) 24 a[j]=1; 25 } 26 } 27 int count=0; 28 for (int i = 0; i < num; ++i) 29 { 30 if(a[i]==0) 31 count++; 32 } 33 printf("%d\n",count-1); 34 } 35 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4603509.html