#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, bool> elem;

int main()
{
    vector<elem> is_prime(10000 + 1);

    is_prime.at(0) = elem(0, false);
    is_prime.at(1) = elem(1, false);

    for (size_t i = 2; i < is_prime.size(); i++) {
        is_prime.at(i) = elem(i, true);
    }

    for (size_t i = 2; i < is_prime.size() / 2; i++) {
        if (is_prime.at(i).second) {
            for (size_t j = i * 2; j < is_prime.size(); j += i) {
                is_prime.at(j).second = false;
            }
        }
    }

    int n;
    while (cin >> n && n != 0) {
        int sum = 0;

        size_t i = 2;
        while (n--) {
            while (!is_prime.at(i).second) {
                i++;
            }
            sum += is_prime.at(i).first;
            i++;
        }

        cout << sum << endl;
    }

    return 0;
}