def ascan; gets.split.map(&:to_i);end

require 'prime'

pr = []
g = Prime::EratosthenesGenerator.new
while (t = g.next) < 250000
    pr << t
end


while (n = gets.to_i) != 0
    p pr.bsearch_index{|x| 2*n < x} - pr.bsearch_index{|x| n < x}
end
