### BUGGY CODE ###

def create_prime_list(limit):
    """ ??¨??????????????????????????§limit?????§????´???°?????????????±???????
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    #print('x={0}'.format(x))
    nums = [x for x in range(2, limit+1)]
    while nums[0]<=x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x%current_prime != 0]
    primes.extend(nums)
    #print(primes)
    return primes


def solve(n):
    primes = create_prime_list(110000)
    primes = primes[:n]
    return primes


def is_prime(q, k=50):
    """ ??????????????????????´???°?????????????????¨??????????????????????????°????´???°???????????????????????????
    http://d.hatena.ne.jp/pashango_p/20090704/1246692091
    """
    import random
    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


def find_nth_prime(n):
    """ n???????????§????´???°????±??????? """
    count = 0
    num = 2
    result = []
    while True:
        if is_prime(num):
            count += 1
            result.append(num)
        if count >= n:
            break
        num += 1
        #print(count, num)
    print(result)
    return result


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

        # ????????¨???????????¨???
        # result = find_nth_prime(data)
        result = solve(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]))