def prime(n)
  primes = Array.new(n + 1){|i|i}
  primes[1] = nil
  for i in 2..n ** 0.5
    if primes[i]
      for j in 2..n / i
        primes[i * j] = nil
      end
    end
  end
  return primes.select{|i|i} # !> shadowing outer local variable - i
end
def main(input = STDIN)
  primes = prime(104743)
  while (n = input.gets.to_i) != 0
    puts primes[0..n].inject{|i, sum|i + sum}
  end
end
main