sosuu = Array.new(1000001,true)
sosuu[0] = false
sosuu[1] = false
sosuu2 = []
i = 0
while i < 1000001
 if sosuu[i]
  sosuu2 << i
  s = 2
  k = s * i
  while k < 1000001
   sosuu[k] = false
   s += 1
   k = s * i
  end
 end
 i += 1
end

n = gets.to_i
until n == 0
 ans = 0
 i = 0
 while i < n
  w = sosuu2[i]
  ans += w
  i += 1
 end

 puts ans

 n = gets.to_i
end
