### BUGGY CODE ###

from math import sqrt, ceil, pow

class SieveOfAtkin:
    """ ??¢???????????????
    https://github.com/mccricardo/sieve_of_atkin/blob/master/sieve_of_atkin.py
    """
    def __init__(self, limit):
        self.limit = limit
        self.primes = []
        self.sieve = [False] * (self.limit + 1)

    def flip(self, prime):
        try:
            self.sieve[prime] = True if self.sieve[prime] == False else False
        except KeyError:
            pass

    def invalidate(self, prime):
        try:
            if self.sieve[prime] == True: self.sieve[prime] = False
        except KeyError:
            pass

    def isPrime(self, prime):
        try:
            return self.sieve[prime]
        except KeyError:
            return False

    def getPrimes(self):
        testingLimit = int(ceil(sqrt(self.limit)))

        for i in range(testingLimit):
            for j in range(testingLimit):
                # n = 4*i^2 + j^2
                n = 4 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and (n % 12 == 1 or n % 12 == 5):
                    self.flip(n)

                # n = 3*i^2 + j^2
                n = 3 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and n % 12 == 7:
                    self.flip(n)

                # n = 3*i^2 - j^2
                n = 3 * int(pow(i, 2)) - int(pow(j, 2))
                if n <= self.limit and i > j and n % 12 == 11:
                    self.flip(n)

        for i in range(5, testingLimit):
            if self.isPrime(i):
                k = int(pow(i, 2))
                for j in range(k, self.limit, k):
                    self.invalidate(j)

        self.primes = [2, 3] + [x for x in range(len(self.sieve)) if self.isPrime(x) and x >= 5]
        return self.primes



def find_nth_prime(n):
    """ n???????????§????´???°????±??????? """
    A = SieveOfAtkin(110000)
    A.getPrimes()
    primes = A.primes[:n]
    return primes


if __name__ == '__main__':
    # ??????????????\???
    while True:
        data = int(input())
        if data == 0:
            break

        # ????????¨???????????¨???
        result = find_nth_prime(data)
        print(sum(result))

### FIXED CODE ###

import random

def is_prime(q, k=50):
    """ ??????????????????????´???°?????????????????¨??????????????????????????°????´???°???????????????????????????
    http://d.hatena.ne.jp/pashango_p/20090704/1246692091
    """
    q = abs(q)
    # ?¨???????????????§?????????????????§????????????????????????
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False

    # n-1=2^s*d??¨????????????a?????´??°???d????\???°)???d????±???????
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # ?????????k?????°?????????
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]??????????????????????????§??????
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True


Primes = []
def find_nth_prime(n):
    """ n??????????´???°????±??????? """
    count = len(Primes)
    if count >= n:
        return
    if count > 0:
        num = Primes[-1] + 1
    else:
        num = 2
    while True:
        if is_prime(num):
            count += 1
            Primes.append(num)
        if count >= n:
            break
        num += 1


if __name__ == '__main__':
    # ??????????????\???
    while True:
        data = int(input())
        if data == 0:
            break

        # ????????¨???????????¨???
        find_nth_prime(data)
        # print(Primes)
        print(sum(Primes[:data]))