| ||||||||||
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 |
Re:坑。。。In Reply To:Re:坑。。。 Posted by:yueyibo at 2016-11-21 12:32:55 > http://blog.csdn.net/luckcircle/article/details/53248376 #include<stdio.h> #include<string.h> const int MAX=10005; bool isprime[10005]; int prime[1230],top=0,num[10005]; void init(){ memset(isprime,true,sizeof(isprime)); for(int i=2;i<MAX;i++){ if(isprime[i]){ prime[top++]=i; for(int j=i*2;j<MAX;j+=i){ isprime[j]=false; } } } } void solve(){ int sum; memset(num,0,sizeof(num)); for(int i=0;i<top;i++){ sum=0; for(int j=i;j<top;j++){ sum=sum+prime[j]; if(sum>10000){ break; } num[sum]++; } } } int main(){ int n; init(); solve(); while(scanf("%d",&n)!=EOF&&n){ printf("%d\n",num[n]); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator