标签:des style blog http color os strong io
Time Limit: 1000MS | Memory Limit: 65536K | |
Description
Input
Output
Sample Input
2 3 4 5 0
Sample Output
1 3 5 9
Source
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 int n,phi[1001000],tot,prime[500000]; 5 long long sum[1001000]; 6 bool check[1000100]; 7 void PHI(int n){ 8 phi[1] = 1; 9 for(int i=2;i<=n;i++){ 10 if(!check[i]){ 11 prime[++tot] = i; 12 phi[i] = i - 1; 13 } 14 for(int j=1;j<=tot;j++){ 15 if(prime[j]*i>n) break; 16 check[prime[j]*i] = true; 17 if(i%prime[j]==0){ 18 phi[i*prime[j]] = phi[i] * prime[j]; 19 break; 20 }else phi[i*prime[j]] = phi[i] * (prime[j]-1); 21 } 22 } 23 } 24 25 int main(){ 26 PHI(1000000); 27 sum[2] = 1; 28 for(int i=3;i<=1000000;i++) sum[i]+=sum[i-1] + phi[i]; 29 while(scanf("%d",&n)!=EOF && n) cout<<sum[n]<<endl; 30 return 0; 31 }
POJ2478 Farey Sequence,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/kjerome/p/3866501.html