import Data.Set (toList, fromList, findMax, delete)
import Data.List (foldl')
 
main = interact $ unlines . map (show . goldbach . read) . init . lines
 
goldbach x = if odd x then 0 else goldbach' p (reverse p)
 where
  p = takeWhile (<= x) $ primes (2:[3,5..x])
  goldbach' (p1:ps1) (p2:ps2)
   | p1 == p2   = if p1+p2==x then 1 else 0
   | p1+p2 < x  = goldbach' ps1 (p2:ps2)
   | p1+p2 > x  = goldbach' (p1:ps1) ps2
   | p1+p2 == x = 1 + goldbach' ps1 ps2
 
primes = toList . (seive 2) . fromList  
 
seive p xs  
 | p*p > findMax xs = xs  
 | otherwise = seive (p+1) $ foldl' (\acc x -> delete x acc) xs [2*p,3*p..q]  
  where q = findMax xs  