Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么超时啊 有谁看看了#include<stdio.h> int prime[100000]; int p[100000]; int t[100000]; __int64 a[1000010]; void PRIME(int M) {int i,j,k; prime[1]=2; prime[2]=3; k=2; for(i=5;i<=M;i+=2) { for(j=2;prime[j]*prime[j]<=i;j++) { if(i%prime[j]==0)goto loop; } k++;prime[k]=i; loop:; } prime[0]=k; } int Int(int n) {int i,s,k; k=n; for(i=1;i<=prime[0];i++) { s=0; while(n%prime[i]==0){s++;n/=prime[i];} if(s>0) { k=k/prime[i]*(prime[i]-1); } if(n==1)break; if(n/prime[i]<prime[i]) { k=k/n*(n-1);break;} } return k; } int main() { int x,i,ans; int c,d; PRIME(1000); a[1]=0; for(i=2;i<=1000000;i++) a[i]=a[i-1]+Int(i); while(scanf("%d",&x)!=EOF) { if(x==0) break; printf("%I64d\n",a[x]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator