import math

def pri(n):

    if n < 2:

        return False

    elif n == 2:

        return True

    elif n % 2 == 0:

        return False



    i = 3

    while i <= math.sqrt(n):

        if n % i == 0:

            return False

        i += 2

    return True



l=[i for i in range(110000)if pri(i) ]



while True:

    n = int(eval(input()))

    if n == 0: break

    print((sum(l[:n])))
import math

def pri(n):

    l =[True] * n

    l[0] = l[1] = False

    for i in range(2,n):

        if l[i]:

            for j in range(i*2, n, i):

                l[j] = False

    return l

n=105000

s=pri(n)

l=[i for i in range(n) if s[i]]

while True:

    n = int(eval(input()))

    if n == 0: break

    print((sum(l[:n])))
import math


def pri(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return True


l = [i for i in range(110000) if pri(i)]
while True:
    n = int(eval(input()))
    if n == 0:
        break
    print((sum(l[:n])))

import math


def pri(n):
    l = [True] * n
    l[0] = l[1] = False
    for i in range(2, n):
        if l[i]:
            for j in range(i * 2, n, i):
                l[j] = False
    return l


n = 105000
s = pri(n)
l = [i for i in range(n) if s[i]]
while True:
    n = int(eval(input()))
    if n == 0:
        break
    print((sum(l[:n])))

-    if n < 2: -        return False -    elif n == 2: -        return True -    elif n % 2 == 0: -        return False -    i = 3 -    while i <= math.sqrt(n): -        if n % i == 0: -            return False -        i += 2 -    return True +    l = [True] * n +    l[0] = l[1] = False +    for i in range(2, n): +        if l[i]: +            for j in range(i * 2, n, i): +                l[j] = False +    return l -l = [i for i in range(110000) if pri(i)] +n = 105000 +s = pri(n) +l = [i for i in range(n) if s[i]]