#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    const long long N = 105000;
    vector<bool> F(N, true);
    vector<long long> Prime;

    for(long long i = 2; i < (long long)sqrt(N); i++){
        if(F[i]){
            Prime.push_back(i);
            for(long long j = i + i; j <= N; j += i){
                F[j] = false;
            }
        }
    }

    long long ps = Prime.size();
    vector<long long> A(ps + 1, 0);
    for(long long i = 0; i < ps; i++){
        A[i + 1] += A[i] + Prime[i];
    }

    long long n;
    while(cin >> n){
        if(n == 0) break;
        cout << A[n] << endl;
    }

    return 0;
}
