include Math

def fetch_prime_list(max)
  list = (2..max).to_a
  prime_list = []
  sqrt = Math.sqrt(max).floor

  while val = list.shift
    prime_list << val
    if val > sqrt
      break
    end
    list.delete_if{|num| num % val == 0}
  end
  return prime_list.concat(list)
end

prime = fetch_prime_list(105000)
while true do
    n = gets.to_i
    if n == 0
        break
    end
   
    sum = 0
    for a in 0..n - 1 do
        c = prime[a]
        sum += c.to_i
    end
    puts sum
end

