Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

# 0以上整数x未満の素数のリストを返す(0,1は含まない)
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

import bisect

def main():
    N = 10**5+1
    ps = primes(N)
    P = [0]*N
    for p in ps:
        P[p] = 1

    Q = int(input())
    for _ in range(Q):
        ans = 0
        l,r = map(int, input().split())
        li = bisect.bisect_left(ps, l)
        ri = bisect.bisect_right(ps, r)
        for i in range(li, ri):
            if P[(ps[i]+1)//2]:
                ans += 1
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input=sys.stdin.readline

# 0以上整数x未満の素数のリストを返す(0,1は含まない)
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def main():
    N = 10**5+1
    ps = primes(N)

    P = [0]*N
    for p in ps:
        P[p] = 1

    ruisekiwa = [0]*N
    for i in range(3, N, 2):
        if P[i] and P[(i+1)//2]:
            ruisekiwa[i] = 1
    for i in range(3, N):
        ruisekiwa[i] += ruisekiwa[i-1]
    
    Q = int(input())
    for _ in range(Q):
        l,r = map(int, input().split())
        ans = ruisekiwa[r] - ruisekiwa[l-1]
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

# 0以上整数x未満の素数のリストを返す(0,1は含まない)
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

import bisect

def main():
    N = 10**5+1
    ps = primes(N)
    P = [0]*N
    for p in ps:
        P[p] = 1

    Q = int(input())
    for _ in range(Q):
        ans = 0
        l,r = map(int, input().split())
        li = bisect.bisect_left(ps, l)
        ri = bisect.bisect_right(ps, r)
        for i in range(li, ri):
            if P[(ps[i]+1)//2]:
                ans += 1
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input=sys.stdin.readline

# 0以上整数x未満の素数のリストを返す(0,1は含まない)
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def main():
    N = 10**5+1
    ps = primes(N)

    P = [0]*N
    for p in ps:
        P[p] = 1

    ruisekiwa = [0]*N
    for i in range(3, N, 2):
        if P[i] and P[(i+1)//2]:
            ruisekiwa[i] = 1
    for i in range(3, N):
        ruisekiwa[i] += ruisekiwa[i-1]
    
    Q = int(input())
    for _ in range(Q):
        l,r = map(int, input().split())
        ans = ruisekiwa[r] - ruisekiwa[l-1]
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

# 0以上整数x未満の素数のリストを返す(0,1は含まない)
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def main():
    N = 10**5+1
    ps = primes(N)
    P = [0]*N
    for p in ps:
        P[p] = 1

    Q = int(input())
    for _ in range(Q):
        ans = 0
        l,r = map(int, input().split())
        for i in range(l, r+1):
            if P[i] and P[(i+1)//2]:
                ans += 1
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input=sys.stdin.readline

# 0以上整数x未満の素数のリストを返す(0,1は含まない)
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def main():
    N = 10**5+1
    ps = primes(N)

    P = [0]*N
    for p in ps:
        P[p] = 1

    ruisekiwa = [0]*N
    for i in range(3, N, 2):
        if P[i] and P[(i+1)//2]:
            ruisekiwa[i] = 1
    for i in range(3, N):
        ruisekiwa[i] += ruisekiwa[i-1]
    
    Q = int(input())
    for _ in range(Q):
        l,r = map(int, input().split())
        ans = ruisekiwa[r] - ruisekiwa[l-1]
        print(ans)

if __name__ == '__main__':
    main()