Sum of Consecutive Primes


Description
Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime 
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. 
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero.
Output
The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.
1つの数nに対して,順序素数で加算できる場合数を求める.41,41=2+3+5+7+11,41=11+13+17,41=41のように41に対して3つのケースがある
問題解決の考え方:
(1)解素数については,スクリーニング法を用いて素数を求めることができる.例えば1~100内の素数の全てを解く:まず1を除外してから3~100の数を2で除いて、後の数が2で割り切れるとその数が素数ではないことを説明し、その数を削除する.次に残りの数を3で割るようにして、素数ではない数を掘り、残りは素数です
(2)最終結果,すなわち順序素数で加算できる場合数については,逐次遍歴法を用いてタイムアウトしない.最初の素数から、加算された和がその数以上になるまで後に加算し、最後にその数に等しいか否かを判断し、等しい場合は説明が可能である.
#include <iostream>
#include <math.h>
#include <string.h>
#define MAX 10005
using namespace std;
bool isPrime[MAX];
int prime[MAX];
int prime_num;

void getPrime(){
    int maxV = sqrt(MAX);
    memset(isPrime, true, sizeof(isPrime));
    for (int i = 2; i < maxV; i++) {   //         
        if (isPrime[i]) {
            for (int j = i+1; j < MAX; j++) {
                if (j%i == 0) {
                    isPrime[j] = false;
                }
            }
        }
    }
    prime_num = 0;
    for (int i = 2; i < MAX; i++) {  //               
        if (isPrime[i]) {
            prime[prime_num++] = i;
        }
    }
}
int main(int argc, const char * argv[]) {
    // insert code here...
    getPrime();
    int n;
    while (cin >> n) {
        if (n == 0 || n < 2 || n > 10000) break;
        int result = 0;
        for (int i = 0; i < prime_num; i++) {
            int sum  = prime[i];
            if (sum  > n) break;
            int j = i+1;      //   i       ,        
            while (sum < n) {
                sum += prime[j++];
            }
            if (sum == n) {
                result ++;
            }
        }
        cout << result << endl;
    }
    return 0;
}