require 'prime'

### constant

MAX_P = 10000

### main

pnums = Prime.each(MAX_P).to_a

loop do
  n = gets.to_i
  break if n == 0
  #p ["n", n]
  
  count = 0
  i0 = i1 = 0
  sum = 0

  loop do
    if sum < n
      break if pnums[i1].nil? || pnums[i1] > n
      sum += pnums[i1]
      i1 += 1
    elsif sum > n
      sum -= pnums[i0]
      i0 += 1
    else
      count += 1
      sum -= pnums[i0]
      i0 += 1
    end
  end    
  p count
end