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<cstdio> #include<cstring> int n; int a[10010],b[10010]; void shu() { memset(a,0,sizeof(a)); for(int i=2;i<=10010;i++) { if(a[i]==0) { for(int j=2;j*i<=10010;j++) a[j*i]=1; } } } int main() { shu(); while(scanf("%d",&n)!=EOF) { if(n==0) break; int t=0,cnt=0,k,ans=0; for(int i=2;i<=n;i++) { if(a[i]==0) b[t++]=i; } for(int i=0;i<t;i++) { k=i; while(cnt<=n) { cnt=cnt+b[k++]; if(cnt==n) { ans++; cnt=n+1; } } cnt=0; } printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator