require 'prime'
 
primes = Prime.each(1_000_000).to_a
 
while (n = gets.to_i) > 0
    i = 0
    j = (primes.find_index{|x| x > n} || primes.size) - 1
 
    count = 0
    while
        s = primes[i] + primes[j]
        count += 1 if s == n
        break if i == j
        if s < n
            i += 1
        else
            j -= 1
        end
    end
    p count
end