#include <iostream>
using namespace std;

#define prime 104729
#define sqrt_prime 324
#define check if (!not_prime[i])

int main() {
	int sum, num, in; bool not_prime[prime + 1];
	not_prime[0] = true; not_prime[1] = true;
	for (int i = 2; i <= sqrt_prime; i++) {
		check for (int j = i + i; j <= prime; j += i) {
			not_prime[j] = true;
		}
	}
	while (1) {
		cin >> in; if (in == 0) break; sum = 0; num = 0;
		while (in != 0) {
			num++; if (!not_prime[num]) { sum += num; in--; }
		}
		cout << sum << endl;
	}
	return 0;
}
