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> using namespace std; int prime[5000]; int cnt; bool mark[10005]; int number[10005]; int sum[10005]; int main(){ int i,j,k,n; cnt=1; memset(mark,false,sizeof(mark)); memset(number,0,sizeof(number)); for(i=2;i<=10000;i++){ if(!mark[i]){ prime[cnt++]=i; } for(j=1;j<cnt&&i*prime[j]<=10000;j++) mark[i*prime[j]]=true; } memset(sum,0,sizeof(sum)); for(i=1;i<cnt;i++) sum[i]+=sum[i-1]+prime[i]; for(i=1;i<cnt;i++){ for(j=i;j<cnt;j++){ sum[j]-=sum[i-1]; if(sum[j]<=10000) number[sum[j]]++; } } while(1){ scanf("%d",&n); if(n==0) break; printf("%d\n",number[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