Title: Sum of Prime Numbers

Given a positive integer n, find the sum of the first n prime numbers. For example, when n = 9, the sum is 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 = 100.

Input:
Multiple datasets are provided. Each dataset contains an integer n (n ≤ 10000). The input ends when n equals 0. There are no more than 50 datasets.

Output:
For each dataset, output the sum s on a new line.

Sample Input:
2
9
0

Output for the Sample Input:
5
100

# Buggy version:
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) ]

print(len(l))

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

# Fixed version:
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(input())
    if n == 0: break
    print(sum(l[:n]))

# Buggy version:
import itertools
n=104730;a=list(range(n));a[:2]=0,0
for i in range(2,323):
 a[i*2::i]=[0]*len(a[i*2::i])
p=list(itertools.compress(range(n),a))
print(len(p))
for e in iter(input,'0'):print(sum(p[:int(e)]))


# Fixed version:
from itertools import *
n=104730;a=list(range(n));a[:2]=0,0
for i in range(2,323):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(range(n),a))
for e in iter(input,'0'):print(sum(p[:int(e)]))

# Buggy version:
import sys
from itertools import *
n=104730;a=list(range(n));a[:2]=0,0
for i in range(2,323):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(range(n),a))
for e in sys.stdin:
 if'0'!=e:print(sum(p[:int(e)]))


# Fixed version:
import sys
from itertools import *
n=104730;a=list(range(n));a[:2]=0,0
for i in range(2,323):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(range(n),a))
for e in sys.stdin:
 if'0\n'!=e:print(sum(p[:int(e)]))

# Buggy version:
import sys

n = 104729
a = [True] * n
a[0] = False
for i in range(2,n):
	if(a[i-1]):
		for j in range(i**2-1, n, i):
			a[j] = False
a = [i[0]+1 for i in enumerate(a) if i[1]]

for s in sys.stdin:
	if s == '0':
		exit()
	print(sum(a[:int(s)]))

# Fixed version:
import sys

n = 104729
a = [True] * n
a[0] = False
for i in range(2,n):
	if(a[i-1]):
		for j in range(i**2-1, n, i):
			a[j] = False
a = [i[0]+1 for i in enumerate(a) if i[1]]

for s in sys.stdin:
	n = int(s)
	if n == 0:
		exit()
	print(sum(a[:n]))

# Buggy version:
N = 104723
p = [1]*(N + 1)
for i in range(4, N + 1, 2): p[i] = 0
a = [2]
for i in range(3, N + 1, 2):
    if p[i] == 1:
        a.append(a[-1] + i)
        for j in range(3*i, N + 1, 2*i): p[j] = 0
print(len(a))

while True:
    n = int(input())
    if n == 0: break
    print(a[n - 1])

# Fixed version:
N = 104743
p = [1]*(N + 1)
for i in range(4, N + 1, 2): p[i] = 0
a = [2]
for i in range(3, N + 1, 2):
    if p[i] == 1:
        a.append(a[-1] + i)
        for j in range(3*i, N + 1, 2*i): p[j] = 0

while True:
    n = int(input())
    if n == 0: break
    print(a[n - 1])