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 |
我0ms,212k,敢问8k怎么编的?#include<stdio.h> #include<iostream> using namespace std; int sum[2001],t,n,p[10001],ans; int main() {int i,j; for(i=2;i<=10000;i++) if(p[i]==0) for(j=i*i;j<=10000;j+=i) p[j]=1; for(i=2;i<=10000;i++) if(p[i]==0) {t++; sum[t]=sum[t-1]+i; } while(scanf("%d",&n)&&n!=0) {ans=0;i=1;j=0; while(i>j) {if(sum[i]-sum[j]==n) ans++; i++; while(sum[i]-sum[j]>n) j++; } 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