
require 'prime'

until (n = gets.to_i) == 0
    res = 0
    if n.odd?
        puts Prime.prime?(n-2)?1:0
    else
        primes = Prime.each(n/2+1).each do |p|
            res += (Prime.prime?(n - p))?1:0
        end
        puts res
    end
end