max=110000
array=[*2..max]
2.upto(Math.sqrt(max)) do |num1|
    array.reject! do |num2|
        (num2%num1==0)&&(num2>num1)
        end
    end
while gets
    break if $_.to_i==0
    x=0
    for i in 0...$_.to_i
        x+=array[i]
        end
    puts x
end