primes = (2..10000).to_a
primes.each do |prime|
	primes.reject!{|num| num != prime and num % prime == 0}
end

while (number = gets.chomp.to_i) > 0
	candidates = primes.select{|prime| prime <= number}
	b, e = 0, 0
	answer = 0
	for b in 0..candidates.size - 1
		for e in b..candidates.size - 1
			answer += 1 if candidates[b..e].inject(:+) == number
		end
	end
	puts answer
end