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) (takeWhile (<= div x 2) primes)
 where
  primes = 2 : sieve [3, 5 .. x]
   where
    isqrt = (truncate . sqrt . fromIntegral) x
    sieve (p : xs)
     | p > isqrt = p : xs
     | otherwise = p : sieve [x | x <- xs, rem x p /= 0]