{-# OPTIONS_GHC -O3 -fexpose-all-unfoldings -fdicts-cheap -fdicts-cheap #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.List (intersect)
import Data.Array.Unboxed
import Data.Set (difference,size,fromList)

main = do
  s <- readLn
  if s == 0
     then return ()
     else do
       let ps  = fromList $ primesToA s
           ps' = fromList $ map ((-) s) (primesToA s)
           gb  = difference ps ps'
           ans =(size ps) -  (size gb)
       print $ if odd ans then (div ans 2) + 1 else div ans 2

       main

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]] :: UArray Int Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a