require 'prime'
n = 287117
a = Array.new(n){|i| i+1}
a[0] = 0
(2..n**(0.50)).each do |i|
  (2..(n/i)).each{|j| a[i*j-1] = 0} if a[i-1]>0
end
a.delete(0)

while (m=gets.to_i)>0
  c=0
  a.each_with_index do |i, idx|
    break if i>(m/2)
    c+=1 if (m-i).prime?
  end
  p c
end