prime_array = Array.new(10001){true}
prime_array[0] = false
prime_array[1] = false
10001.times do |i|
  next unless prime_array[i]
  for j in 2..(10000 / i) do 
    prime_array[i * j] = false
  end
end
non_pure_primes = prime_array.map.with_index do |tf, i|
  i if tf
end
pure_primes = non_pure_primes.find_all{|prime| !prime.nil?}
while true
  counter = 0
  head_index = 0
  queue = [pure_primes[0]]
  given_number = gets.to_i
  break if given_number == 0
  while true
    queue_sum = queue.inject(0){|sum, number| sum + number}
    counter += 1 if queue_sum == given_number
    if queue_sum < given_number
      head_index += 1
      break if pure_primes[head_index] > given_number
      queue.push(pure_primes[head_index])
    else
      queue.shift
    end
  end
  puts counter
end