#include <iostream>
#include <algorithm>
using namespace std;

const int MAX = 11000;
bool isPrime[MAX];

void next(int& k) {
    do {
        k++;
    } while (isPrime[k] == false);
}

int main() {
    fill_n(isPrime, MAX, true);
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = i * 2; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int min = 2, max = 2, res = 0, sum = 2;
        while (min <= n) {
            if (sum < n) {
                next(max);
                sum += max;
            } else {
                if (sum == n) {
                    res++;
                }
                sum -= min;
                next(min);
            }
        }
        cout << res << endl;
    }
}