#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <unordered_set>

using namespace std;

#define ll long long

ll p[10001];
vector<ll> prime;

int main(){
  for(ll i = 0; i < 10001; i++){
    p[i] = 0;
  }
  p[0] = p[1] = 1;
  
  ll id = 2;
  while(1){
    while(id <= 10000 &&  p[id] == 1){
      id++;
    }
    if(id >= 10000){
      break;
    }
    ll temp = 2 * id;
    while(temp <= 10000){
      p[temp] = 1;
      temp += id;
    }
    id++;
  }

  for(ll i = 0; i <= 100; i++){
    //    cout << i << ' ' << p[i] << endl;
  }

  for(ll i = 2; i <= 10000; i++){
    if(p[i] == 0){
      prime.push_back(i);
    }
  }

  for(vector<ll>::iterator it = prime.begin(); it != prime.end(); it++){
    //   cerr << *it << ' ';
  }
  //  cerr << '\n';
  
  ll n = prime.size();
  vector<ll> sum(n);
  sum[0] = prime[0];
  unordered_set<ll> us;
  us.insert(sum[0]);
  for(ll i = 1; i < n; i++){
    sum[i] = sum[i-1] + prime[i];
    us.insert(sum[i]);
  }
  us.insert(0);

  ll k;
  while(cin >> k && k){
    ll cnt = 0;
    for(ll i = 0; i < n; i++){
      if(us.find(k+sum[i]) != us.end() || k == sum[i]){

	cnt ++;
      }
    }
    cout << cnt << endl;
  }
}
  