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 |
baneHunter打表#include <cstdio> #include <cstring> using namespace std; const int MAXN=10005; bool isPrime[MAXN]; int prime[MAXN],top; void init() { memset(isPrime,true,sizeof(isPrime)); for(int i=2;i<MAXN;i++) { if(isPrime[i]) { prime[top++]=i; for(int j=i+i;j<MAXN;j+=i) isPrime[j]=false; } } } int counter[MAXN]; int total[MAXN]; void solve() { total[1]=prime[0]; for(int i=2;i<=top;i++) total[i]=total[i-1]+prime[i-1]; for(int l=1;l<=top;l++) { for(int i=1;i+l<=top+1;i++) { int sum=total[i+l-1]-total[i-1]; if(sum<MAXN) counter[sum]++; } } } int main() { init(); solve(); int n; while(scanf("%d",&n)!=EOF&&n!=0) { printf("%d\n",counter[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