require 'prime'
require 'set'
loop {
    n = gets.to_i
    break if n == 0
    primes = Set[*Prime.each(n).to_a]
    c = primes.count{|x| primes.include?(n-x)}
    p n.even? && primes.include?(n/2) ? (c-1)/2+1 : c/2
}