import Data.List
import Data.Array

erst :: Int->([Int],[Int])->[Int]
erst nmax (tosearch, primes)
    | x*x >= nmax  = sort $ primes' ++ tosearch'
    | otherwise    = erst nmax (tosearch', primes')
    where
        x = head tosearch
        tosearch' = [n|n<-(tail tosearch),(n`mod`x)/=0]
        primes' = primes ++ [x]

nmax = 10000 :: Int
primes = erst nmax (filter odd [3..nmax], [2])

s :: Int->Int
s n = sum $ take n primes

solve :: String->IO ()
solve str = do
    let n = read str :: Int
    if n==0 then return () else print (s n) 

main :: IO ()
main = do
    str <- getContents
    mapM_ solve $ lines str