
#include "bits/stdc++.h"
using namespace std;

int main() {
	int n;

	while (cin >> n) {
		if(!n)break;
		vector<int> vi;
		int sum = 0;
		int data[10005] = { 0 };
		for (int i = 0; i < 10005; ++i) {
			data[i] = i;
		}
		for (int i = 2; i <= sqrt(10005); ++i) {
			for (int j = i * 2; j <= 10005; j = j + i) {
				data[j] = 0;
			}
		}
		for (int i = 2; i <= 10005; ++i) {
			if (data[i])vi.push_back(data[i]);
		}
		for (int i = 0; i < n; ++i) {
			sum+=vi[i];
		}
		cout << sum<< endl;
	}
}