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

const int MAX = 1000000;
bool IsPrime[MAX];
vector<int> Eratosthenes(int n = MAX) {
    vector<int> res;    // prime numbers
    IsPrime[0] = false; IsPrime[1] = false;
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) if (IsPrime[i]) {
        res.push_back(i);
        for (int j = i * 2; j < n; j += i) IsPrime[j] = false;
    }
    return res;
}

int main() {
    vector<int> prime = Eratosthenes();
    vector<int> acc(prime.size() + 1, 0);
    for (int i = 0; i < prime.size(); i++) {
        acc[i + 1] = acc[i] + prime[i];
    }
    int n;
    while (cin >> n, n) {
        cout << acc[n] << endl;
    }
    return 0;
}
