#include <cstdio>
#include <vector>
using namespace std;

bool isnp[10001];
int ans[10001];

int main(){
	for(int i = 2; i < 98; ++i){
		if( !isnp[i] ){
			for(int j = i * i; j <= 10000; j += i){
				isnp[j] = true;
			}
		}
	}

	vector<int> primes;
	for(int i = 2; i < 9999; ++i){
		if( !isnp[i] ) primes.push_back(i);
	}

	vector<int> sum(primes.size() + 1);
	for(int i = 0; i < primes.size(); ++i){
		sum[i+1] = sum[i] + primes[i];
	}

	for(int i = 1; i < sum.size(); ++i){
		for(int j = 0; j < i; ++j){
			if(sum[i] - sum[j] <= 10000){
				++ans[sum[i] - sum[j]];
			}
		}
	}
	
	int n;
	while(scanf("%d", &n), n != 0){
		printf("%d\n", ans[n]);
	}
}