require 'prime'
MAX = 10000
dp = [0] * 10001
primes = Prime.each.take_while{ |p| p < MAX }
(1..1/0.0).each do |i|
  break if primes[0,i].reduce(:+) > MAX
  primes.each_cons(i) do |ps|
    break if (sum = ps.reduce(:+)) > MAX
    dp[sum] += 1
  end
end

while n = gets.to_i
  break if n == 0
  puts dp[n]
end