#include <iostream>
#include <string>
using namespace std;

int main()
{
	long n, pn, sum;
	long prime[10002];
	while (1){
		cin >> n;
		if (n==0)
		{
			break;
		}
		prime[1] = 2;
		pn = 3;		//pn = prime[i-1] + 1
		sum = prime[1];
		int i = 2;
		while (i <= n){
			int flag = 0;
			for (int j = 1; j<i; j++){
				if (pn % prime[j] == 0){     //pnより小さい素数で割り切れなければ、pnは素数
					flag++;
				}
			}
			if (flag == 0){
				prime[i] = pn;
				sum += prime[i];
				i++;
			}
			pn++;
		}
		cout << sum << endl;
	}
	return 0;
}