#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int n;
  bool bprime[10001];
  fill(bprime, bprime + 10001, true);
  vector<int> prime;
  FOR(i,2,10001){
    if(bprime[i]){
      for(int j = i * i; j < 10001; j+=i) bprime[j] = false;
      prime.push_back(i);
    }
  }
  int count[10001] = {};
  FORIT(it, prime){
    int t = 0;
    for(vector<int>::iterator it2 = it; it2 != prime.end(); it2++){
      t += *it2;
      if(t > 10000) break;
      count[t]++;
    }
  }
  while(cin>>n,n){
    cout<<count[n]<<endl;
  }

  return 0;
}