#include <cstdio>
#include <algorithm>
using namespace std;
int primes[10001];

bool isPrime(int n) {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()  {

    primes[1] = 2;
    primes[2] = 5;
    int idx = 3, num = 4;
    while (idx <= 10000) {
        if (isPrime(num)) {
            primes[idx] = primes[idx-1] + num;
            idx++;
        }
        num++;
    }
    int n;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        printf("%d\n", primes[n]);
    }
    return 0;
}

