#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int N=11111;
    vector<int> ps(N);
    rep(i,N)ps[i]=i;
    ps[0]=ps[1]=0;
    for(int i=2;i<N;i++){
        if(!ps[i])continue;
        for(int j=i+i;j<N;j+=i){
            ps[j]=0;
        }
    }
    ps.erase(remove(ps.begin(),ps.end(),0),ps.end());
    int sum[11111]={};
    rep(i,ps.size()){
        sum[i+1]=sum[i]+ps[i];
    }

    int cnt[11111]={};
    rep(i,ps.size())rep(j,i){
        if(sum[i]-sum[j]>11111)continue;
        cnt[sum[i]-sum[j]]++;
    }
    int n;
    while(cin>>n && n) cout << cnt[n] << endl;
}