#include<iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
	bool p[10001] = {0};
	rep(i, 10001)if(i>1&&!p[i])for(int j = i+i; j < 10001; j+=i)p[j]=1;
	int n, c, s;
	while(cin>>n, n){
		c = 0;
		rep(i, 9999){
			s = 0;
			if(p[i+2])continue;
			for(int l=i+2; l<=n && s<n; l++){
				
				if(!p[l])s+=l;
			}
			if(s==n)c++;
		}
		cout<<c<<endl;
	}
	return 0;
}