#include <iostream>
#include <vector>
using namespace std;
int main() {
  const long N = 1000000;
  vector<bool> p(N, true); p[0] = p[1] = false;
  int i, j, n, a, c;
  for (i = 2; i * i < N; i++) {
    if (!p[i]) continue;
    for (j = i * i; j < N; j += i) p[j] = false;
  }
  while (cin >> n, n) {
    a = 0, c = 0;
    for (i = 0; a < n; i++) if (p[i]) { a++; c += i; }
    cout << c << endl;
  }
}