#include<iostream>
using namespace std;
bool flag[10010];
int p[10000];

void era(int n){
	int l = 0;
	for (int i = 2; i < 12*n && flag[i]==false; i++){
		p[l++] = i;
		for (int j = i; j < 12 * n; j += i){
			flag[j] = true;
		}
	}
}

int main(){
	int n = 1;
	while (cin >> n, n != 0){
		era(n);
		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += p[i];
		}
		cout << sum << endl;
	}

}