Problem:


素数の和

p(i) を小さい方から i 番目の素数とします。例えば、7 は、2, 3, 5, 7 と小さい方から 4 番目の素数なので、p(4) = 7 です。

n が与えられたとき、i = 1 から n までの p(i) の和 s

s = p(1) + p(2) + .... + p(n)

を出力するプログラムを作成してください。例えば、n = 9 のとき、s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 = 100 となります。

Input

複数のデータセットが与えられます。各データセットに整数 n  (n ≤ 10000) が与えられます。n が 0 のとき入力の最後とします。データセットの数は 50 を超えません。

Output

各データセットの n に対して、s を１行に出力して下さい。

Sample Input

2
9
0

Output for the Sample Input

5
100



Sample input:
2
9
0


Sample output:
5
100

Submission status: Accepted

Solution code:
import sys

PRIMES=[]
SIEVES=[]
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)+1
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h:
            N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    return N
def prime(n):
    global SIEVES
    if SIEVES==[]: SIEVES=sieve(n)
    primes =[2]+filter(None,SIEVES[:n/2])
    return primes
PRIMES=prime(105000)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print sum(PRIMES[:n])

Submission status: Accepted

Solution code:
import sys
def prime(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    N[0]=2
    return filter(None,N)
PRIMES=prime(105000)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print sum(PRIMES[:n])

Submission status: Accepted

Solution code:
import math

r = 200000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print sum

Submission status: Accepted

Solution code:
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print sum

Submission status: Accepted

Solution code:
import math
 
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

prime = [0 for i in range(11000)]
j = 0
for i in range(len(p)):
    if p[i]:
        prime[j] = i+1
        j += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Accepted

Solution code:
import math
 
prime = [0 for i in range(11000)]
k = 0
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        prime[k] = i+1
        k += 1
        l = i
        for j in range(2*i+1,r,i+1):
            p[j] = 0


for i in range(l+1,r):
    if p[i]:
        prime[k] = i+1
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Accepted

Solution code:
import math
 
prime = [0 for i in range(11000)]
k = 0
r = 104900
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        prime[k] = i+1
        k += 1
        l = i
        for j in range(2*i+1,r,i+1):
            p[j] = 0


for i in range(l+1,r):
    if p[i]:
        prime[k] = i+1
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Accepted

Solution code:
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print s[n-1]

Submission status: Accepted

Solution code:
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print s[n-1]

Submission status: Accepted

Solution code:
import sys
def prime(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    N[0]=2
    return filter(None,N)
PRIMES=prime(105000)
while 1:
    n = input()
    if n==0: break
    s = sum(PRIMES[:n])
    print s

Submission status: Accepted

Solution code:
import sys
def prime(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    N[0]=2
    return filter(None,N)
PRIMES=prime(105000)
while 1:
    n=input()
    if n==0: break
    print sum(PRIMES[:n])

Submission status: Accepted

Solution code:
def prime(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    N[0]=2
    return filter(None,N)
PRIMES=prime(105000)
while 1:
    n=input()
    if n==0: break
    print sum(PRIMES[:n])

Submission status: Accepted

Solution code:
def sieve(n):
    a = range(n)
    a[:2] = None, None
    for i in range(2, n):
        if i ** 2 >= n: break
        if not a[i]: continue
        for i in range(i ** 2, n, i):
            a[i] = None
    return [v for v in a if v]

def partialsum(a):
    b = [0] + a
    for i in range(len(a)):
        b[i + 1] += b[i]
    return b

a = partialsum(sieve(200000))
while True:
    n = int(raw_input())
    if n == 0: break
    print a[n]

Submission status: Accepted

Solution code:
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

prime_list = sieve(200000)
while 1:
    a = input()
    if a == 0:
        break
    print sum(prime_list[:a])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
def prime_checker(n, option = False) -> list:
    p = [False, True, False, False, False, True] * (n // 6 + 1)
    del p[n + 1:]
    p[1 : 4] = False, True, True
    for x in range(5, int(n**.5 + 1)):
        if p[x]:
            p[x * x :: 2*x] = [False] * ((n // x - x) // 2 + 1)
    return [e for e, q in enumerate(p) if q] if option else p

from itertools import accumulate
*p, = accumulate([0] + prime_checker(105010, True))
for i in [*map(int, open(0))][:-1]:
    print(p[i])

Submission status: Accepted

Solution code:
import math
M = 104729
lst = list(range(M+1))

for i in range(0, M+1, 2):
    lst[i] = 0

lst[1] = 0
lst[2] = 2

for i in range(3, math.ceil(math.sqrt(M+1)), 2):
    if lst[i]:
        for j in range(i**2, M+1, i):
            lst[j] = 0

anslst = [i for i in lst if i != 0]

while True:
    n = int(input())
    if n == 0 :
        break

    print(sum(anslst[:n]))

Submission status: Accepted

Solution code:
import math

isPrime = [True] * 110001
primes = [];
def eratos(n):
    isPrime[0] = isPrime[1] = False
    for i in range(2,int(math.sqrt(n))):
        if isPrime[i]:
            j = 2 * i
            while j <= n:
                isPrime[j] = False
                j = j + i
    for i in range(2,110000):
        if isPrime[i]:
            primes.append(i)
eratos(110000)

while True:
    try:
        p = int(input())
        if p == 0:
            break
        ans = 0
        for i in range(0,p):
            ans += primes[i]
        print(ans)
    except:
        break

Submission status: Accepted

Solution code:
import math
MAX=104729
ROOT=int(math.sqrt(MAX))

#素数以外をはじく
prime=[True for i in range(MAX+1)]

def prime_list(prime):
    #2は除外
    for i in range(2,MAX,2):
        prime[i]=False
    #要素を持つか
    for x in range(3,ROOT+1):
        if prime[x]==True:
            for j in range(x*x,MAX,x):
                prime[j]=False
                
prime_list(prime)

total=[0 for g in range(MAX)]
def append(total):
    j=total[1]=2
    for i in range(3,len(prime)):
        if prime[i]==True:
            total[j]+=total[j-1]+i
            j+=1

append(total)


while True:
    n=int(input())
    if n==0:
        break
    print(total[n])

Submission status: Accepted

Solution code:
num = 200000
L = [True] * (num+1)
L[0] = False
L[1] = False
for i in range( 2, int(num**0.5)+ 2 ):
    if not L[i]:
        continue
    for j in range(i*2, num+1, i):
        L[j] = False

p = [ x for x in range(num+1) if L[x] ]

while True:
    n = int(input())
    if n == 0:
        break
    print(sum(p[0:n]))

Submission status: Accepted

Solution code:
p = [1] * (110000 + 1)
p[0], p[1] = 0, 0
for i in range(2, int(110000 ** 0.5) + 1):
    if not p[i]:
        continue
    for j in range(2 * i, 110000 + 1, i):
        p[j] = 0

p_num = [i for i in range(110000) if p[i] == 1]

while 1:
    n = int(input())
    if n == 0:
        break
    print(sum(p_num[:n]))

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

P = mymath.pnum_eratosthenes(105000)

while True:
    N = int(input())

    if N == 0:
        break

    print(sum(P[:N]))

Submission status: Accepted

Solution code:
Max=1000000
Sqrt=1000
def prime_number():
    count=[]
    prime=[True for i in range(Max)]
    for i in range(4,Max,2):
        prime[i]=False
    for i in range(3,Sqrt,2):
        if prime[i]==True:
            for j in range(i*2,Max,i):
                prime[j]=False       
    for k in range(2,Max):
        if prime[k]==True:
            count.append(k)
    return count
box=prime_number()
while 1:
    try:
        ans=0
        N=int(input())
        if N==0:break
        for i in range(N):
            ans +=box[i]
        print(ans)
    except:break

Submission status: Accepted

Solution code:
import math
count=2
i=3
prime=[2,3]
for i in range(5,1000000,2):
    if count==10000:break
    check=1
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            check=0
            break
    if check==1:
        prime.append(i)
        count+=1
while 1:
    n=int(input())
    if n==0:break
    print(sum(prime[:n]))

Submission status: Accepted

Solution code:
from math import sqrt
import sys
sys.setrecursionlimit(100000)

def prime(n):
    p = [1 for i in range(n)]
    p[0] = 0
    prime_ = []
    for i in range(2,int(sqrt(n))):
        if p[i-1] == 1:
            for i in range(2*i,n,i):
                p[i-1] = 0
    for i in range(n):
        if p[i] == 1:
            prime_.append(i+1)
    return prime_

prime_ = prime(105000)
sum_prime_ = [0 for i in range(10000)]

def sum_prime(n):
    global sum_prime_
    if n == 1:
        sum_prime_[n-1] = prime_[n-1]
        return sum_prime_[n-1]
    else:
        sum_prime_[n-1] = prime_[n-1] + sum_prime(n-1)
        return sum_prime_[n-1]

sum_prime(10000)

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

Submission status: Accepted

Solution code:
from math import sqrt, ceil
from itertools import accumulate
N = 120000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))

cumsum = [i for i in range(N) if temp[i]]
cumsum = list(accumulate(cumsum))
while True:
    n = int(input())
    if not n: break
    print(cumsum[n-1])

Submission status: Runtime Error

Solution code:
import math
n = []
li = [] 
li = [i for i in range(2,100000)]
while li[0] <= int(math.sqrt(100000)):
	n.append(li[0]) 
	sss = li[0] 
	li = [i for i in li if i % sss != 0] 
n.extend(li) 

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

Submission status: Runtime Error

Solution code:
import math
n = []
li = [] 
li = [i for i in range(2,10000)]
while li[0] <= int(math.sqrt(10000)):
	n.append(li[0]) 
	sss = li[0] 
	li = [i for i in li if i % sss != 0] 
n.extend(li) 

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

Submission status: Runtime Error

Solution code:
isPrime = [True] * 10001
sum = 0
sumPrime = [sum]
def calcPrime():
    global sum
    isPrime[0] = isPrime[1] = False
    for i in range(len(isPrime)):
        if(isPrime[i]):
            sum += i
            sumPrime.append(sum)
            for j in range(2 * i, len(isPrime), i):
                isPrime[j] = False
                
calcPrime()
while(True):
    n = input()
    if(n == 0):
        break
    print(sumPrime[n])

Submission status: Runtime Error

Solution code:
def pri(s,n):
    tab=[i for i in range(n+1) if s[i] and i>=2]
    return(tab)
  
s=[True for _ in range(999999+1)]
i=2
while i**2<=999999:
    if s[i]:
        j=i*2
        while j<=999999:
            s[j]=False
            j+=i
    i+=1

s=pri(s,10000)
while True:
    n = int(input())
    if n == 0: break
    sum = 0

    for i in range(n):
        sum += s[i]
    print(sum)

Submission status: Runtime Error

Solution code:
a=map(int,raw_input().split())[1:]
import math
def p(a):
    b,c,i=range(2,2*math.log(a)*a)),[],0
    while len(b)!=0:
        c.append(b[0])
        b=[i for i in b[1:] if i%b[0]!=0]
    return sum(c)
for i in a:print(str(p(i)))

Submission status: Runtime Error

Solution code:
a=map(int,raw_input().split())
a=a[:-1]
import math
def p(a):
    b,c,i=range(2,2*math.log(a)*a)),[],0
    while len(b)!=0:
        c.append(b[0])
        b=[i for i in b[1:] if i%b[0]!=0]
    return sum(c)
for i in a:print(str(p(i)))

Submission status: Runtime Error

Solution code:
import math
def p(a):
    b,c,i=range(2,int(10+2*math.log(a)*a)),[],0
    while len(c)!=a:
        c.append(b[0])
        b=[i for i in b[1:] if i%b[0]!=0]
    return sum(c)
a=map(int,input().split())
for i in a:
    if i!=0:
        print(str(p(i)))
    else:
        break

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

primes = [2]
n = 3
while n < 10000:
    flag = True
    for p in primes:
        if n % p == 0:
            flag = False
            break
    if flag:
        primes.append(n)
    n += 1

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

Submission status: Runtime Error

Solution code:
import sys

pn, tmp = [], [i for i in range(2, 10000)]
while tmp[0] < 100:
    v = tmp.pop(0)
    pn.append(v)
    tmp = list(filter(lambda x: x%v!=0, tmp))
for t in tmp: pn.append(t)

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

Submission status: Runtime Error

Solution code:
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if s[i] and i > 1]

n = []
while True:
    tmp = int(input())
    if tmp == 0:
        break
    n.append(tmp)
m = max(n)
p = sieve(10000)

for i in range(len(n)):
    sum = 0
    for j in range(n[i]):
        sum += p[j]
    print(sum)

Submission status: Runtime Error

Solution code:
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if s[i] and i > 1]

n = []
while True:
    tmp = int(input())
    if tmp == 0:
        break
    n.append(tmp)
m = max(n)
p = sieve(10000)

for i in range(len(n)):
    sum = 0
    if n[i] == 1:
        print(2)
    else:
        for j in range(n[i]):
            sum += p[j]
        print(sum)

Submission status: Runtime Error

Solution code:
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]))

Submission status: Runtime Error

Solution code:
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


def main():
    prime = []
    for i in range(10001):
        if is_prime(i):
            prime.append(i)

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = [0]
M = 10001
p = [1]*M
S = 0
for i in xrange(2,M):
    if p[i]:
        for j in xrange(i*i,M,i):
            p[j] = 0
        S += i; s.append(S)
while 1:
    n = input()
    if n==0: break
    print s[n]

Submission status: Runtime Error

Solution code:
r = 10000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    sum = 0
    for i in range(n):
        if p[i] == 1:
            sum += i
    print sum

Submission status: Runtime Error

Solution code:
import math
r = 10000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num = 0, 1
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i
        i += 1
    print sum

Submission status: Runtime Error

Solution code:
import math
r = 10000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num, sum = 0, 1, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i
        i += 1
    print sum

Submission status: Runtime Error

Solution code:
import math
r = 10000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print sum

Submission status: Runtime Error

Solution code:
import math

r = 100000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print sum

Submission status: Runtime Error

Solution code:
import math
 
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

prime = [0 for i in ranege(10000)]
j = 0
for i in range(len(p)):
    if p[i]:
        prime[j] = i+1
        j += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])import math
 
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

prime = [0 for i in ranege(10000)]
j = 0
for i in range(len(p)):
    if p[i]:
        prime[j] = i+1
        j += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Runtime Error

Solution code:
import math
 
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

prime = [0 for i in range(10000)]
j = 0
for i in range(len(p)):
    if p[i]:
        prime[j] = i+1
        j += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Runtime Error

Solution code:
import math
 
prime = [0 for i in range(11000
k = 0
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        prime[k] = i+1
        k += 1
        l = i
        for j in range(2*i+1,r,i+1):
            p[j] = 0


for i in range(l,r):
    if p[i]:
        prime[k] = i+1
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Runtime Error

Solution code:
import math
 

sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

prime = [0 for i in range(11000)]
prime[0] = 2
k = 0
for i in range(2,r):
    if p[i]:
        prime[k] = i+1+prime[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Submission status: Runtime Error

Solution code:
import math
 

sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 0
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print (n)

Submission status: Runtime Error

Solution code:
import math

sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print (n)

Submission status: Runtime Error

Solution code:
import math

sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print s(n)

Submission status: Runtime Error

Solution code:
import math

sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print s[n-1]

Submission status: Runtime Error

Solution code:
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

prime_list = sieve(200000)
while 1:
    a = input()
    if a == 0:
        break
    prin
    t sum(prime_list[:a])

Submission status: Runtime Error

Solution code:
N = 10000
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])

Submission status: Runtime Error

Solution code:
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])

Submission status: Runtime Error

Solution code:
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

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