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 |
无赖之下In Reply To:好久没打过表了…… Posted by:summery at 2006-08-07 18:39:41 n从2到10000都输出了真确的结果 但就是RTE!!! 我也只好打表了 还请教各位高人能否指出为什么会RTE(本机已正常运行) #include <iostream> #include <math.h> using namespace std; int susu(int n) { if(n<=3)return 1; if(n%2==0)return 0; int middle=(int)sqrt(double(n)); int i; for(i=3;i<=middle;i+=2)//奇数不能被偶数整除 { if(n%i==0)break; } if(i>middle)return 1; else return 0; } int main() { int p[1130]={0}; int i,j; j=1; for(i=2;i<10000;i++)if(susu(i)==1)p[j++]=i; int n; cin>>n; while(n) { int count=0; i=1129; while(n<p[i])i--; j=i; int sum=p[i]; while(i!=0) { if(sum==n) { count++; sum-=p[j]; j--; i--; sum+=p[i]; continue; } else if(sum<n) { i--; sum+=p[i]; } else { sum-=p[j]; j--; } } cout<<count<<endl; cin>>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