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 |
为什么这样都TLE?为什么这样都TLE?在自己的机子上都很快。。。。 #include<stdio.h> #include<math.h> int f(int n) { if(n==1) return 0; else if(n==2) return 1; else { if(n%2==0) return 0; else { int i,t; t=0; for(i=3;i<=sqrt(n);i=i+2) { if(n%i==0) { t=1; break; } } if(t==0) return 1; else return 0; } } } void main() { int i,j,n,m,k,a[84],p,num[431][84],s[84],sum[84]; _int64 total; k=0; for(i=1;i<=431;i++) { if(f(i)==1) a[k++]=i; } for(i=0;i<431;i++) { for(j=0;j<84;j++) { num[i][j]=0; } } for(i=1;i<=431;i++) { for(j=0;j<k;j++) { if(a[j]<=i) { if(i%a[j]==0) { p=i; while(p%a[j]==0) { num[i-1][j]++; p=p/a[j]; } } } else break; } } while(scanf("%d %d",&n,&m)!=EOF) { if(m>(n-m)) m=n-m; total=1; for(i=0;i<84;i++) { sum[i]=0; s[i]=0; } for(i=n;i>n-m;i--) { for(j=0;j<k;j++) { sum[j]+=num[i-1][j]; } } for(i=m;i>=1;i--) { for(j=0;j<k;j++) { s[j]+=num[i-1][j]; } } for(i=0;i<84;i++) { if((sum[i]-s[i])>0) total*=(sum[i]-s[i]+1); } printf("%I64d\n",total); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator