#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<bool> prime(1000000,true);
    vector<int> p;
    for(int i = 2; i < 1000000; i++)if(prime[i]){
        p.push_back(i);
        for(int j = 2; i*j < 1000000; j++)prime[i*j] = false;
    }
    int n;
    while(cin >> n,n){
        int ans = 0;
        for(int i = 0; i < n; i++)ans += p[i];
        cout << ans << endl;
    }
}

