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<iostream> #include<cmath> using namespace std; bool prime(int n) { int i; if(1<n&&n<4) return 1; else { for(i=2;i<=(int)sqrt(n*1.0);i++) { if(n%i==0)break; } if(n%i==0)return 0; else return 1; } } int main(void) { int a,si,b[20000],g,count,h; cin>>a; while(a) { g=a; si=count=0; while(g>1) { if(prime(g--))b[si++]=g+1; } for(int i=0;i<si;i++) { if(a==b[i])count++; else { h=a; h=h-b[i]; for(int j=i+1;j<si;j++) { if(h==b[j]){count++;break;} else if(h<b[j])break; else h=h-b[j]; } } } cout<<count<<endl; cin>>a; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator