import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm;
import std.bigint;

bool[1000001] p;

void main()
{
  int[10002] sum;
  p[2 .. 1000001] = true;

  for (int i = 2; i <= 1000000; i++){
    if (p[i]){
      for (int j = i * 2; j <= 1000000; j += i){
        p[j] = false;
      }
    }
  }
  for (int i = 1, j = 0; j <= 10000; i++){
    if (p[i]){
      sum[j + 1] = sum[j] + i;
      j++;
    }
  }

  while (true){
    int n = readln().chomp().to!int;
    if (n == 0) break;
    writeln(sum[n]);
  }
}