#include <cstdio>
#include <vector>
using namespace std;

bool sieve[10000001];

int main()
{
	fill(sieve+2, sieve+10000001, true);
	vector<int> prime;
	
	for (int i = 2; i * i <= 10000000; i++){
    	
		if(sieve[i] == false)continue;
		
    	for (int j = i*2; j <= 10000000; j += i){
    	  	sieve[j] = false;
  	  }
	  prime.push_back(i);
  	}
	int n;
	while(scanf("%d", &n), n != 0){
		
		int total=0;
		
		for(int i = 0; i < n; i++){
			total += prime[i];
		}
		
		printf("%d\n", total);
	}
	
	return (0);
}