#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int isPrime[1000001];
int main()
{
  map<int,int>prime;
  fill(isPrime,isPrime + 1000001,1);
  isPrime[0] = isPrime[1] = 0;
  for(int i = 2 ; i*i < 1000001 ; i++ )
    {
      if(isPrime[i]){
	for(int j = i*2 ; j < 1000001 ; j+=i )isPrime[j] = 0;
      }
    }
  int p = 0;
  for(int i = 0 ; i < 1000001 ; i++ )if(isPrime[i])prime[p++] = i;
  int n;
  while(cin >> n,n)
    {
      int sum = 0,res = 0;
      int back = 0,front = 0;
      while(sum >= 0 && front < p){
	if(sum + prime[front] <= n) {
	  sum += prime[front];
	  front++;
	} else if(sum + prime[front] > n) {
	  sum -= prime[back];
	  back++;
	}
	if(sum == n)res++; 
      }
      cout << res << endl;
    }
  return 0;
}