require 'prime'
primes = Prime.each(10000).to_a

while true
  n = gets.to_i
  break if n.zero?
  res = 0
  for i in (0...primes.size) do
    sum = 0
    for j in (i...primes.size) do
      sum += primes[j]
      if(sum == n)
        res += 1
        break
      end 
      break if(sum > n)
    end
  end
  puts res
end