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