#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#include<bitset>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    int it = 0, i = 0;
    bitset<51000> eratos;
    vector<int> prime;
    prime.push_back(2);

    range(j,2,51000)
        eratos[j] = 1;
    eratos[0] = 0;
    eratos[1] = 0;

    while(i < 51000){
        while(1){
            if(eratos[i] == 1){
                prime.push_back(i + 1);
                break;
            }
            i++;
        }
        for(int j = 2; prime[it] * j - 1 < 51000; j++){
            int num = prime[it] * j - 1;
            eratos[num] = 0;
        }
        it++; i++;
    }

    int input;
    while(cin >> input, input){
        int sum = 0;
        rep(i,input){
            sum+= prime[i];
        }
        cout << sum << endl;
    }
}