#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

bool prime[int(1e7)+5];

int main() {
    int m = int(1e7);
    vector<ll> p;
    fill(prime,prime+m+1,true);
    prime[0] = false;
    prime[1] = false;
    for(int i=2;i*i<=m;i++){
        if(prime[i]){
            for(int j=i*i;j<=m;j+=i){
                prime[j] = false;
            }
        }
    }
    p.push_back(0);
    for(ll i=2;p.size()<10005;i++){
        if(prime[i]) p.push_back(i);
    }
    for(int i=0;i<p.size();i++){
        p[i+1] += p[i];
    }
    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        cout << p[n] << endl;
    }
    return 0;
}   

