def primelist( pmax )

	primes = Array.new( pmax + 1 )
	primes[ 0 ] = 0 
	primes[ 1 ] = 0 
	2.upto( pmax ){ |i|
		primes[ i ] = 1
	}

	max = Math.sqrt( pmax ).to_i

	prime = 0
	while true
		(prime+1).upto( pmax ){ |t|
			if primes[ t ] != 0
				prime = t 
				break
			end
		}
		break if prime > max 

		n = 2
		while prime * n <= pmax
			primes[ prime * n ] = 0
			n += 1
		end
	end

	plist = Array.new
	0.upto( pmax ).each{ |n|
		plist << n if primes[ n ] == 1
	}
	plist	
end

def main
	answers = Array.new
	plist = primelist( 1000000 )

	while (n = $stdin.gets.chomp.to_i) != 0

		sum = 0
		0.upto( n - 1 ){ |n|
			sum += plist[ n ]
		}
		answers << sum
	end

	answers.each{ |a|
		puts a
	}
end

main
