def makePrime
  counter = 0
  prime = []

  n_prime = 1000000
  prime_check = Array.new(n_prime, true)
  prime_check[0] = prime_check[1] = false

  for i in 2...n_prime
    if prime_check[i]
      prime << i
      j = i*2
      while j < n_prime
        prime_check[j] = false
        j += i
      end
    end
  end

  return prime
end

prime = makePrime
while input = gets
  n = (input.chomp).to_i
  if n == 0
    break
  end

  sum = 0
  for i in 0...n
    sum += prime[i]
  end

  puts sum
end