#include <cmath>
#include <iostream>
#include <vector>
typedef std::vector <int> vi;
vi PRIMES;
vi prime(int n){
	vi s,p;
	int i,j,x,h;
	for (i=1;i<=n;i+=2) s.push_back(i);
	h=s.size();
	for (i=1;i<=(int)pow(n,0.5);i++)
		if (x=s[i]) for (j=i+x;j<h;j+=x) s[j]=0;
	s[0]=2;
	for (i=0;i<h;i++) if(s[i]!=0) p.push_back(s[i]);
	return p;
}
int main(void){
	int n,s,i;
	PRIMES=prime(105000);
	while (true){
		std::cin>>n; if (n==0) break;
		s=0;
		for (i=0;i<n;i++) s+=PRIMES[i];
		std::cout<<s<<"\n";
	}
}