primes = Enumerator.new {|y|
	ps = [2]
	cp = 3
	y << 2
	while true 
		if ps.take_while {|x|
			x*x <= cp
		}.all? {|x|
			cp % x != 0
		}
			y << cp
			ps.push cp
		end
		cp+=2
	end
}
cache = Enumerator.new {|y|
	primes.inject {|a,b|
		y << a
		a+b
	}
}.take(10000).to_a
while (n = gets.to_i)!= 0
	puts cache[n-1]
end 