#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define M 10001
int main()
{
  bool isPrime[M]={false,false};
  for(int i=2;i<M;i++)isPrime[i]=true;
  for(int i=2;i<M;i++)for(int j=i+i;j<M;j+=i)isPrime[j]=false;

  vector<int>sum;
  sum.push_back(0);
  for(int i=2;i<M;i++)if(isPrime[i])sum.push_back( i+sum.back() );

  int n;
  while(cin>>n,n){
    int count=0;
    for(vector<int>::iterator it=sum.begin();it!=sum.end();it++){
      if( binary_search(it, sum.end(), *it + n) ) count++;
    }
    cout<<count<<endl;
  }
}