import Control.Monad (unless)

primes :: Integral a => [a]
primes = 2 : sieve [3] [3, 5 ..]
    where
        sieve (x : xs) ys = let (ps, qs) = span (< x * x) ys
            in ps ++ sieve (xs ++ ps) [z | z <- qs, mod z x /= 0]

sumOfPrimes :: Int -> Int
sumOfPrimes = sum . flip take primes

main :: IO ()
main = do
    n <- readLn
    unless (n == 0) $ do
        (putStrLn . show . sumOfPrimes) n
        main