#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

bool sosuu[1000000] = {false};
int a;

int main(){
	int x;
	int p = 1000000;
	x = floor(sqrt(p));
	for(int i = 2; i < x+1; i++){
		if(sosuu[i] == true){
			continue;
		}
		for(int j = 2*i; j < p+1; j = j+i){
			sosuu[j] = true;
		}
	}
	while(cin >> a){
		if(a == 0) break;
		ll ans = 0;
		int t = 0;
		for(int i = 2; i < p+1; i++){
			if(sosuu[i] == false){
				t++;
				ans += i;
				if(t == a) break;
			}
		}
		cout << ans	<< endl;
	}
}