Buggy python submission (verdict: Time Limit Exceeded):
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    Q = int(input())
    ma = 10 ** 5 + 1
    dp = [0] * ma
    dp[2] = 1

    for i in range(3,ma,2):
        if dp[i] == 0:
            dp[i] = 1
            if dp[(i + 1) // 2] == 1 or dp[(i + 1) // 2] == 2:
                dp[i] = 2
            for j in range(i * 2,ma,i):
                dp[j] = 3

    for _ in range(Q):
        l,r = map(int,input().split())
        print(dp[l:r+1].count(2))

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    Q = int(input())
    ma = 10 ** 5 + 1
    dp = [0] * ma
    dp[2] = 1

    for i in range(3,ma,2):
        if dp[i] == 0:
            dp[i] = 1
            if dp[(i + 1) // 2] == 1 or dp[(i + 1) // 2] == 2:
                dp[i] = 2
            for j in range(i * 2,ma,i):
                dp[j] = 3

    ruiseki = [0] * ma

    for i in range(1,ma):
        if dp[i] == 2:
            ruiseki[i] = ruiseki[i-1] + 1
        else:
            ruiseki[i] = ruiseki[i-1]

    for _ in range(Q):
        l,r = map(int,input().split())
        print(ruiseki[r] - ruiseki[l-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
ma = 10 ** 5 + 1
dp = [0] * ma
dp[2] = 1

for i in range(3,ma,2):
    if dp[i] == 0:
        dp[i] = 1
        if dp[(i + 1) // 2] == 1 or dp[(i + 1) // 2] == 2:
            dp[i] = 2
        for j in range(i * 2,ma,i):
            dp[j] = 3

for _ in range(Q):
    l,r = map(int,input().split())
    print(dp[l:r+1].count(2))

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    Q = int(input())
    ma = 10 ** 5 + 1
    dp = [0] * ma
    dp[2] = 1

    for i in range(3,ma,2):
        if dp[i] == 0:
            dp[i] = 1
            if dp[(i + 1) // 2] == 1 or dp[(i + 1) // 2] == 2:
                dp[i] = 2
            for j in range(i * 2,ma,i):
                dp[j] = 3

    ruiseki = [0] * ma

    for i in range(1,ma):
        if dp[i] == 2:
            ruiseki[i] = ruiseki[i-1] + 1
        else:
            ruiseki[i] = ruiseki[i-1]

    for _ in range(Q):
        l,r = map(int,input().split())
        print(ruiseki[r] - ruiseki[l-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def trial_division(n):
    prime_factors = list()
    while n % 2 == 0:
        prime_factors.append(2)
        n //= 2
    p = 3
    while p * p <= n:
        if n % p == 0:
            prime_factors.append(p)
            n //= p
        else:
            p += 2
    if n != 1:
        prime_factors.append(n)
    return prime_factors

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

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    Q = int(input())
    ma = 10 ** 5 + 1
    dp = [0] * ma
    dp[2] = 1

    for i in range(3,ma,2):
        if dp[i] == 0:
            dp[i] = 1
            if dp[(i + 1) // 2] == 1 or dp[(i + 1) // 2] == 2:
                dp[i] = 2
            for j in range(i * 2,ma,i):
                dp[j] = 3

    ruiseki = [0] * ma

    for i in range(1,ma):
        if dp[i] == 2:
            ruiseki[i] = ruiseki[i-1] + 1
        else:
            ruiseki[i] = ruiseki[i-1]

    for _ in range(Q):
        l,r = map(int,input().split())
        print(ruiseki[r] - ruiseki[l-1])

if __name__ == "__main__":
    main()