#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

ll n, p[1000005]={},sum=0;


void prime_number(ll n){
    for(ll i=2; i*i<=1000000; i++){
        for(ll j=i*2; j*j<=10000000; j+=i){
            p[j]=1;
        }
    }
}

int main()
{
    
    while(1){
        cin>>n;
        prime_number(n);
        if(n==0)break;
        ll p_num = 0;
        
        for (ll i = 2; i <= 1000000; i++)
        {
            if (p_num == n)
                break;
            if (p[i] == 0)
            {
                p_num++;
                sum += i;
            }
        }
        cout<<sum<<endl;
        sum = 0;
    }
    
}