标签:
1 #include<iostream> 2 #include<stdio.h> 3 #include<vector> 4 #include<math.h> 5 #include<algorithm> 6 #define FOR for 7 #define M 10009 8 using namespace std; 9 10 vector<int> coll; 11 bool prim1[M]; 12 void give_list(); 13 14 int main() 15 { 16 //freopen("acm.acm","r",stdin); 17 give_list(); 18 vector<int>::iterator pos; 19 vector<int>::iterator pos1; 20 int sum; 21 int num; 22 int ans; 23 while(cin>>num,num) 24 { 25 ans = 0; 26 for(pos = coll.begin(); pos != coll.end(); ++ pos) 27 { 28 sum = *pos; 29 if(*pos > num/2+1) 30 break; 31 for(pos1 = pos+1; pos1 != coll.end(); ++ pos1) 32 { 33 sum += *pos1; 34 if(sum > num) 35 break; 36 else if(sum == num) 37 { 38 ++ ans; 39 break; 40 } 41 } 42 } 43 if(prim1[num]) 44 cout<<++ans<<endl; 45 else 46 cout<<ans<<endl; 47 } 48 } 49 void give_list() 50 { 51 int i; 52 int j; 53 memset(prim1,true,sizeof(bool)*M); 54 prim1[1] = false; 55 for(i = 2; i < sqrt(long double(M))+1; i ++) 56 { 57 if(prim1[i]) 58 { 59 j = 2*i; 60 while(j < M) 61 { 62 prim1[j] = false; 63 j += i; 64 } 65 } 66 } 67 for(i = 2; i < M; i ++) 68 { 69 if(prim1[i]) 70 { 71 coll.push_back(i); 72 } 73 } 74 75 }
标签:
原文地址:http://www.cnblogs.com/gavinsp/p/4568672.html