#include <cstdio>
#include <math.h>

int dp[10001];
int primelist[10001];

int rec(int n){
	if(dp[n] != -1) return dp[n];
	if(dp[n] == 0) return dp[n] = 0;
	return dp[n] = rec(n-1) + primelist[n];
}
int main(){
	bool prime[100000];
	int n;
	
	for(int i = 0; i < 10001; i++) dp[i] = -1;
	for(int i = 0; i < 100000; i++) prime[i] = true;
	prime[0] = prime[1] = false;
	for(int i = 2; i < sqrt(100000); i++){
		if(prime[i]){
			for(int j = 2; i * j < 100000; j++)	prime[i*j] = false;
		}
	}
	
	int c = 0;
	for(int i = 0; i < 100000; i++){
		if(prime[i]){
			primelist[c] = i;
			c++;
		}
		if(c > 10001) break;
	}
	rec(10000);
	while(scanf("%d", &n) != EOF){
		if(n == 0) break;
		printf("%d\n", dp[n-1]);
	}
	return 0;
}