s = [0]

M = 10**6

p = [1]*M

S = 0

for i in range(2,M):

    if p[i]:

        for j in range(i*i,M,i):

            p[j] = 0

        S += i; s.append(S)

while 1:

    n = eval(input())

    if n==0: break

    print(s[n])
s = [0]

M = 104850

p = [1]*M

S = 0

for i in range(2,M):

    if p[i]:

        for j in range(i*i,M,i):

            p[j] = 0

        S += i; s.append(S)

while 1:

    n = eval(input())

    if n==0: break

    print(s[n])
s = [0]
M = 10**6
p = [1] * M
S = 0
for i in range(2, M):
    if p[i]:
        for j in range(i * i, M, i):
            p[j] = 0
        S += i
        s.append(S)
while 1:
    n = eval(input())
    if n == 0:
        break
    print(s[n])

s = [0]
M = 104850
p = [1] * M
S = 0
for i in range(2, M):
    if p[i]:
        for j in range(i * i, M, i):
            p[j] = 0
        S += i
        s.append(S)
while 1:
    n = eval(input())
    if n == 0:
        break
    print(s[n])

-M = 10**6 +M = 104850