#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#define int long long
using namespace std;
vector<int>p, ps;
bool b[5736397];
void f(int k) {
	p.push_back(k);
	ps.push_back(ps.back() + k);
	b[ps.back()] = 1;
	return;
}
signed main() {
	ps.push_back(0); b[0] = 1;
	f(2);
	for (int i = 3; i <= 10000; i += 2) {
		bool b00l = 1;
		for (int j = 0; j < p.size(); j++) 
			if (i%p[j] == 0)b00l = 0;
		if (b00l)f(i);
	}
	int n;
	while (cin >> n, n) {
		int ans = 0;
		for (int i = 0; i < ps.size(); i++) {
			if (ps[i] - n < 0)continue;
			if (b[ps[i] - n])ans++;
		}
		cout << ans << endl;
	}
}
