main = interact $ unlines . map (show . goldbach . read) . takeWhile (/="0") . lines

goldbach x = if odd x then 0 else length $ filter (\p -> elem (x-p) primes_) _primes
 where
  _primes = takeWhile (<= (div x 2)) primes
  primes_ = dropWhile (< (div x 2)) $ takeWhile (<x) primes

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]