array = []
while array[array.length-1]!=0
	array << gets.chomp.to_i
end
array.pop

def prime_sifting(num)
  range = (2..num).to_a
  prime = 2
  i=2
  non_prime_arr = []

  while prime <= Math.sqrt(num)
    for i in 2..num 
      if prime * i <= num
        non_prime_arr << prime * i
      else
        break
      end
    end 
    prime +=1
  end

  return range - non_prime_arr
end

sosu = prime_sifting(100000)

array.each do |a|
	n,j,k = 0,0,1
  sum = sosu[0]
	while k < sosu.length && sosu[j]<=a
    add_next = true
    sum = add_next ? sum + sosu[k] : sum - sosu[j-1]
		if sosu[j..k].inject(:+) == a
			n = n+1
      j = j+1
      add_next = false
		elsif sosu[j..k].inject(:+) > a
			j = j+1
      add_next = false
		else
			k = k+1
      add_next = true
		end
	end
	p n
end