max = 104730
prime = [2]
list = Array.new(max){|i| i}
list[0] = 0
list[1] = 0
loop do
  a = prime[-1]
  break if a >= Math.sqrt(max)
  i = a
  while i <= max
    list[i] = 0
    i += a
  end
  while list[a] == 0
    a += 1
  end
  prime << list[a]
  list[a] = 0
end
prime += list - [0]

while n = gets.to_i
  break if n == 0
  puts prime[0,n].inject(:+)
end