
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i<n;i++)

using namespace std;

bool PrimeCheck(int number)
{
	for(int i = number - 1;i>1;i--)
		if((number%i) == 0)
		{	return false;}
	return true;
}
int main (){

	int d = 0;
	vector<int>v(10008,0);
	vector<int>v2(10008,0);
	rep(i,10002)
		v[i+1] = i+1;
	for(int k = 1; k<10001;k++)
	{
		if(PrimeCheck(v[k+1]))
		{
			//cout << v[k+1] << " ";
			v2[d] = v[k+1];
			d++;
		}
	}
//	cout << v2[d-1] << endl;
//	cout << d << endl;
	int number;
	while(cin >> number,number)
	{
		int answer = 0;
		rep(i,number)
		{
			answer += v2[i];
			//cout << v2[i] << " " ;
		}
		cout  << /*<< "answer is " <<*/answer << endl;
	    
	}
	return 0;
}