import std.stdio, std.string, std.conv;

enum N = 110000;
enum M = 10000;
immutable hurui = {
    bool[N + 1] table;
    table[] = true;
    table[0 .. 2] = false;
    for(int i = 2; i * i <= N; ++i)
    {
        if(table[i])
        {
            for(int j = 2; i * j <= N; j++)
            {
                table[i * j] = false;
            }
        }
    }
    return table;
}();

immutable res = {
    int[M + 1] table;
    int sum, index;
    for(int i = 1; i <= N && index < M; ++i)
    {
        if(hurui[i]) table[++index] = (sum += i);
    }
    return table;
}();

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