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 |
用scanf printf就对的,用cin cout就错了#include<iostream> using namespace std; bool prime[10000]; int main() { int i,j; memset(prime,true,sizeof(prime)); for(i=2;i<100;i++) { if(prime[i]) { for(j=i*i;j<10000;j+=i) prime[j]=false; } } int n,sum,count; while(cin>>n,n) { for(i=2,count=0;i<=n;i++) { if(!prime[i]) continue; for(j=i,sum=0;j<=n;j++) { if(!prime[j]) continue; sum+=j; if(sum<n) continue; else if(sum==n) { count++; break; } else break; } } cout<<count<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator