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 |
这题整郁闷了 结果和打表一样 然后就WA了 然后就只好打表了。。。附代码 哪位大牛给看看。。。 #include <stdio.h> #include <math.h> int prime[10000]; int main() { int i,j; for(i=2;i<10000;i++) prime[i]=1; for(i=2;i<100;i++) { for(j=2;j*i<10000;j++) { if(prime[i*j]) prime[i*j]=0; } } j=0; int p[1500]; for(i=0;i<10000;i++) { if(prime[i]) { p[j]=i; j++; } } int n; scanf("%d",&n); while(n) { int sum=0; int total=0; if(prime[n]) sum++; for(i=0;p[i]<n;i++) { total=0; for(j=i;p[j]<n;j++) { total+=p[j]; if(total>n) break; else if(total==n) { sum++; break; } } } printf("%d\n",sum); scanf("%d",&n); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator