primes = Array.new(1_000_000, true)
primes[0, 2] = [false, false]
2.upto(999_999){|x|
    if primes[x]
        m = 2
        while x * m <= 999_999
            primes[x * m] = false
            m += 1
        end
    end
}

while true
    n = gets.to_i
    break if n == 0
    sum = 0
    3.upto(n/2){|x| sum += 1 if primes[x] && primes[n - x]}
    puts sum
end

