#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    vector<int> ps;
    int max_p;

    ps.reserve(10000);

    ps.push_back(max_p = 2);

    int n, sum;
    bool f;
    while (true) {
        cin >> n;
        if (n == 0) break;
        while (ps.size() < n) {
            max_p++;
            f = true;
            for (int i = 0; ps[i] * ps[i] <= max_p; i++) {
                if (max_p % ps[i] == 0) {
                    f = false;
                    break;
                }
            }
            if (f) ps.push_back(max_p);
        }
        sum = 0;
        for (int i = 0; i < n; i++) {
            sum += ps[i];
        }
        cout << sum << endl;
    }

    return 0;
}