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 |
我的是252K ……63Ms 求改进#include<iostream> using namespace std; int main() { int s=0,n,K=0,M=0,a[1229]={0}; while(cin>>n) { if(n==0) break; int i,j; for(i=2;i<=n;i++) { for(j=2;j*j<=i;j++) if(i%j==0) break; if(j*j>i) a[K++]=i; } for(i=0;i<K;i++) { for(j=i;i<K;j++) { M+=a[j]; if(M<n)continue; else if(M>n){M=0;break;} else {s++;M=0;break;} } } cout<<s<<endl; s=0; K=0; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator