#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

bool isPrime(int n){
    for(int i=2; i<n; i++){
        if((n%i)==0) return false;
    }
    return true;
}

int main() {
    int n; cin>>n;
    while(n != 0){
        //素数列挙
        vector<int> prime;
        for(int i=2; i<=n; i++){
            if(isPrime(i)) prime.push_back(i);
        }

        //累積和
        vector<int> c(prime.size()+1);
        for(int i=1; i<c.size(); i++){
            c[i] = c[i-1] + prime[i-1];
        }

        int count = 0;

        //二分探索
        for(int i=0; i<c.size(); i++){
            int left = i, right = c.size();
            while(left < right){
                int mid = (left+right)/2;
                int sum = c[mid]-c[i];
                if(sum > n) right = mid;
                else left = mid+1;
                if(sum == n){
                    count++;
                }
            }
        }
        cout << count << endl;
        cin>>n;
    }
}

