Problem p03476 (python)

Fixed submission:
from itertools import accumulate
# エラトステネスの篩
# is_prime := 1~nが素数か否か
# table := 2~nのうち素数
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


Q = int(input())
L = [0]*Q
R = [0]*Q

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))

max_R = max(R)
is_prime, table = sieve(max_R)

check = [0]*(max_R + 1)
for i in range(0, max_R + 1):
    if (i % 2 == 1):
        if (is_prime[i-1] and is_prime[(i+1)//2-1]):
            check[i] = 1

# 累積和
check = [0] + check
check = list(accumulate(check))

for i in range(Q):
    print(check[R[i] + 1] - check[L[i]])

Buggy submission (verdict: Runtime Error):
import itertools

def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return table

prime = sieve(5*10**4)
acu = [0] * ((5*10**4)//2+1)
for i in range(1,(5*10**4)//2+1):
    k = (i-1) * 2 +1
    if k in prime and (k+1)//2 in prime:
        acu[i] = acu[i-1] + 1
    else:
        acu[i] = acu[i-1]

q = int(input())

for i in range(q):
    l,r = map(int,input().split())
    li = (l-1) // 2
    ri = (r-1) // 2
    print(acu[ri+1]-acu[li])

Buggy submission (verdict: Runtime Error):
import itertools

def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return table

prime = sieve(5*10**4)
acu = [0] * ((5*10**4)//2+1)
for i in range(1,(5*10**4)//2+1):
    k = (i-1) * 2 +1
    if k in prime and (k+1)//2 in prime:
        acu[i] = acu[i-1] + 1
    else:
        acu[i] = acu[i-1]

q = int(input())

for i in range(q):
    l,r = map(int,input().split())
    li = (l-1) // 2
    ri = (r-1) // 2
    print(acu[ri+1]-acu[li])

Buggy submission (verdict: Runtime Error):
#　n以下の整数の素数列挙（エラトステネスの篩）
#-------------------------------------------------------------------------
import numpy as np

def eratosthenes(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum
#-------------------------------------------------------------------------
from itertools import accumulate

N = int(input())
L = [0] * N
R = [0] * N
A = eratosthenes(10*5)
B = [0] * 10*5
C = [0] * N

for i in range(10*5):
    if i in A:
        if (i+1)/2 in A:
            B[i] = 1

C = [0] + list(accumulate(B)) #out of rangeの回避

for i in range(N):
    L[i], R[i] = map(int, input().split())
for i in range(N):
    print(C[R[i]+1]-C[L[i]])

Buggy submission (verdict: Runtime Error):
#　n以下の整数の素数列挙（エラトステネスの篩）
#-------------------------------------------------------------------------
import numpy as np

def eratosthenes(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum
#-------------------------------------------------------------------------
from itertools import accumulate

N = int(input())
L = [0] * N
R = [0] * N
A = eratosthenes(10*5)
B = [0] * 10*5
C = [0] * N

for i in range(10*5):
    if i in A:
        if (i+1)/2 in A:
            B[i] = 1

C = [0] + list(accumulate(B)) #out of rangeの回避

for i in range(N):
    L[i], R[i] = map(int, input().split())
    print(C[R[i]+1]-C[L[i]])