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 |
为什么WA了???#include <iostream> using namespace std; int t[100] = {0}; bool isPrime(int num) { int i = 2; for(;i <= num / 2;i++) { if(num%i == 0) return false; } return true; } void move(int *t,int &length,int &sum) { sum = sum - t[0]; int j=1; for(;j < length;j++){ t[j-1] = t[j]; } length--; } int main(void) { int i; int length; while (cin >> i && i != 0) { int count = 0; int j = 3; int sum = 2; t[0] = 2; length = 1; for(;;j++) { if(sum > i) break; if(sum + j > i && length == 1) { break; } if(sum + j > i) move(t,length,sum); if(isPrime(j)) { sum += j; if(sum > i && length <= 2) { break; } if(sum == i) { count ++; move(t,length,sum); } t[length] = j; length ++; } } if(isPrime(i)) count ++; printf("%d\n",count); //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