import Data.List (intersect)

main = do
  s <- readLn
  if s == 0
    then return ()
    else do
      let ps = takeWhile (< s) primes
          gb = filter (<= (div s 2)) $ intersect ps (map ((-) s) ps)
      print $ length gb
      main

primes = 2:3: filter isPrime [5,7..50000]

isPrime n = all ((>0).(rem n)) $ takeWhile (\x -> x*x <= n) primes