primes :: [Integer]
primes = 2 : filter isPrime [3,5..]
  where isPrime n = n > 1 && foldr (\x acc -> x * x > n || (n `mod` x /= 0 && acc)) True primes

solve :: Int -> Integer
solve n = sum $ take n primes

main :: IO ()
main = getContents >>= mapM_ (print . solve . read) . takeWhile (/="0") . lines