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

vector<int> v;

bool isPrime(int n) {
    for (int i = 0; i < v.size() && v[i] * v[i] <= n; i++) {
        if (n % v[i] == 0) return false;
    }
    return true;
}

int main() {
    v.push_back(2);
    v.push_back(3);
    for (int i = 5; i <= 10000; i += 2) {
        if (isPrime(i)) {
            v.push_back(i);
        }
    }
    
    int sum[v.size() + 1];
    fill(sum, sum + v.size() + 1, 0);
    for (int i = 1; i < v.size() + 1; i++) {
        sum[i] = sum[i - 1] + v[i - 1];
    }
    
    while (true) {
        int n;
        cin >> n;
        if (n == 0) return 0;
        int count = 0;
        for (int i = 1; i < v.size() + 1; i++) {
            if (v[i - 1] > n) break;
            for (int j = 0; j <= i; j++) {
                if (sum[i] - sum[j] == n) {
                    count++;
                }
            }
        }
        cout << count << endl;
    }
}