标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8315 Accepted Submission(s): 4368
1.筛法打表
#include<cstdio> //筛法打表 int main() { int euler[40000]; int CN,n,i,j; for(i=1;i<=32768;i++) euler[i]=i; for(i=2;i<=32768;i++) if(euler[i]==i) { for(j=i;j<=32768;j+=i) euler[j]=euler[j]/i*(i-1); } scanf("%d",&CN); while(CN--) { scanf("%d",&n); printf("%d\n",euler[n]); } }
2.定义法
#include<cstdio> int euler(int n) { int ans=n; for(int i=2;i*i<=n;i++) if(n%i==0) { ans=ans/i*(i-1); while(n%i==0) n/=i; } if(n>1) ans=ans/n*(n-1); return ans; } int main() { int CN; scanf("%d",&CN); while(CN--) { int n; scanf("%d",&n); printf("%d\n",euler(n)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/orchidzjl/p/4275978.html