Buggy python submission (verdict: Runtime Error):
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])

Fixed submission:
import math
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def prime(n):
    seq = list(range(2, n))
    while len(seq) > 0:
        prime = seq.pop(0)
        yield prime
        # 素数で割り切れない数字のリストを作成
        seq = [i for i in seq if not i % prime == 0]

q=int(input())
l = []
r = []
for i in range(q):
    x,y = map(int,input().split())
    l.append(x)
    r.append(y)
ww = max(r)
a = list(prime(ww+1))

#print('a',a)

ans = [0]
for i in range(2,ww+1):
    if i in a:
        if (i+1)/2 in a:
            ans.append(ans[-1]+1)
        else:
            ans.append(ans[-1])
    else:
        ans.append(ans[-1])

#print(ans)

for i in range(0,q):
    if l[i] == 1:
        print(ans[r[i]-1])
    else:
        print(ans[r[i]-1]-ans[l[i]-2])

Fixed submission:
import math
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def prime(n):
    seq = list(range(2, n))
    while len(seq) > 0:
        prime = seq.pop(0)
        yield prime
        # 素数で割り切れない数字のリストを作成
        seq = [i for i in seq if not i % prime == 0]

q=int(input())
l = []
r = []
for i in range(q):
    x,y = map(int,input().split())
    l.append(x)
    r.append(y)

a = list(prime(max(r)+1))
#print('a',a)
c = []
for i in range(len(a)):
    if (a[i]+1)/2 in a:
        c.append(a[i])

c.sort()
#print('c',c)

for i in range(q):
    h = bisect.bisect_left(c,l[i])
    j = bisect.bisect_right(c,r[i])
    print(j-h)

Fixed submission:
import math
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])