#include <iostream>
using namespace std;
int main() {
	int prime[10001], p = 3, psum[10001], n;
	for (int i = 5; i < 10001; i += 2) {
		int f = 0;
		for (int j = 1; prime[j] * prime[j] <= i; j++) {
			if (i % prime[j] == 0) f = 1; break;
		}
		if(!f) prime[p++] = i;
	}
	psum[1] = 2;
	for (int i = 2; i < 10001; i += 2) {
		psum[i] = psum[i - 1] + prime[i];
	}
	while (1) {
		cin >> n;
		if (n==0) break;
		cout << psum[n] << endl;
	}
	return 0;
	
}