Problem p03476 (python)

Fixed submission:
import math 

def prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return 0
    return 1

#エラトステネスのふるい
MAX =100000
is_prime = [1]*(MAX+1)
is_prime[0] = 0 
is_prime[1] = 0
for i in range(2,MAX+1):
    if prime(i) == 1:
        j = i*2
        while j <= MAX:
            is_prime[j] = 0
            j += i

#２０１７のような数かどうか
a = [0]*(MAX+1)
for i in range(0,MAX):
    if i % 2 == 1:
        if is_prime[i]==1 and is_prime[int((i+1)/2)]==1:
            a[i] = 1

#累積和
s = [0] * (MAX+1)
for i in range(0,MAX):
    s[i+1] = s[i] + a[i]

#クエリ処理
Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    r += 1

    print(s[r]-s[l])

Buggy submission (verdict: Runtime Error):
import math
Q = int(input())

def prime(p):
    for i in range(2, int(math.sqrt(p))+1):
        if p % i == 0:
            return False
    return True

# エラトステネスの篩
data = [1]*10**5
data[0], data[1] = 0, 0
for j in range(2, len(data)):
    if prime(j) == True:
        for k in range(j*2, len(data), j):
            data[k] = 0


# 2017 like
for e in range(2, len(data))[::-1]:
    if data[e] == 1 and (e) % 2 == 1:
        if data[int((e+1)/2)] == 0:
            data[e] = 0
    else:
        data[e] = 0
# 累積和
t = [0]*len(data)
for a in range(len(data)-1):
    t[a+1] = t[a] + data[a]

for b in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r+1] - t[l])

Buggy submission (verdict: Runtime Error):
import math
Q = int(input())

def prime(p):
    for i in range(2, int(math.sqrt(p))+1):
        if p % i == 0:
            return False
    return True

# エラトステネスの篩
data = [1]*(10**5+1)
data[0],data[1] = 0,0 #
for j in range(2, 10**5+1):
    if prime(j) == True:
        for k in range(j*2, 10**5+1, j):
            data[k] = 0
# 2017 like
for k in range(2,10**5)[::-1]: #
    if data[k] == 1 and k % 2 == 1:
        if data[int((k+1)/2)] == 0:
            data[k] = 0
    else: #
        data[k] = 0 #
# 累積和
t = [0]*10**5
for a in range(10**5-1):
    t[a+1] = t[a] + data[a]

for b in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r+1] - t[l])

Buggy submission (verdict: Runtime Error):
import math
Q = int(input())

def prime(p):
    for i in range(2, int(math.sqrt(p))+1):
        if p % i == 0:
            return False
    return True

# エラトステネスの篩
data = [1]*10**5
data[0],data[1] = 0,0 #
for j in range(2, 10**5):
    if prime(j) == True:
        for k in range(j*2, 10**5, j):
            data[k] = 0
# 2017 like
for k in range(2,10**5)[::-1]: #
    if data[k] == 1 and k % 2 == 1:
        if data[int((k+1)/2)] == 0:
            data[k] = 0
    else: #
        data[k] = 0 #
# 累積和
t = [0]*10**5
for a in range(10**5-1):
    t[a+1] = t[a] + data[a]

for b in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r+1] - t[l])

Buggy submission (verdict: Runtime Error):
import math 

def prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return 0
    return 1

#エラトステネスのふるい
MAX =100000
is_prime = [1]*(MAX+1)
is_prime[0],is_prime[1] == 0
for i in range(2,MAX+1):
    if prime(i) == 1:
        j = i*2
        while j <= MAX:
            is_prime[j] = 0
            j += i

#２０１７のような数かどうか
a = [0]*(MAX+1)
for i in range(0,MAX):
    if i % 2 == 1:
        if is_prime[i]==1 and is_prime[int((i+1)/2)]==1:
            a[i] = 1

#累積和
s = [0] * (MAX+1)
for i in range(0,MAX):
    s[i+1] = s[i] + a[i]

#クエリ処理
Q = input()
for q in range(Q):
    l,r = map(int,input().split())
    r += 1

    print(s[r]-s[l])