#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

vector<int> primes;
bool primes_table[10000];

void init() {
    primes_table[0] = primes_table[1] = false;
    for (int i = 2; i <= 10000; i++) {
        primes_table[i] = true;
    }

    for (int i = 2; i <= 10000; i++) {
        if (primes_table[i]) {
            for (int j = i + i; j <= 10000; j+=i) {
                primes_table[j] = false;
            }
        }
    }

    for (int i = 2; i <= 10000; i++) {
        if (primes_table[i]) {
            primes.push_back(i);
        }
    }
}

int main() {
    init();
    int n;
    while (cin >> n) {
        if (n == 0) break;
        cout << accumulate(primes.begin(), primes.begin()+n, 0) << endl;
    }
    return 0;
}

    