Buggy python submission (verdict: Time Limit Exceeded):
def check(i):
    num=int(i**0.5)
    if i==1:return 0
    if i==2:return 1
    for j in range(2,num+1):
        if i%j==0:break

    else:return 1
    return 0
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]

L=[0]*(10**5)#1~100000
for i in range(1,10**5):
    L[i]=check(i+1)

for l,r in lr:
    cnt=0
    for i in range(l,r+1,2):
        if L[i-1]==0:continue
        if L[(i+1)//2-1]==0:continue
        cnt+=1

    print(cnt)

Fixed submission:
q=int(input())
l=[list(map(int,input().split())) for i in range(q)]

def jud(i):
    #iの素数判定
    num=int(i**0.5)+1
    for k in range(2,num):
        if i%k==0:
            return 0
    return 1

s=[0]*(10**5+1)
for i in range(2,10**5+1):
    if i%2==0:
        s[i]=s[i-1]
    else:
        if jud(i)*jud((i+1)//2)==1:
            s[i]=s[i-1]+1
        else:
            s[i]=s[i-1]

for k,v in l:
    ans=s[v]-s[k-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def check(i):
    num=int(i**0.5)
    if i==1:return 0
    if i==2:return 1
    for j in range(2,num+1):
        if i%j==0:break

    else:return 1
    return 0
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]

for l,r in lr:
    cnt=0
    for i in range(l,r+1,2):
        if check(i):
            next_num=int((i+1)//2)
            cnt+=check(next_num)
    print(cnt)

Fixed submission:
q=int(input())
l=[list(map(int,input().split())) for i in range(q)]

def jud(i):
    #iの素数判定
    num=int(i**0.5)+1
    for k in range(2,num):
        if i%k==0:
            return 0
    return 1

s=[0]*(10**5+1)
for i in range(2,10**5+1):
    if i%2==0:
        s[i]=s[i-1]
    else:
        if jud(i)*jud((i+1)//2)==1:
            s[i]=s[i-1]+1
        else:
            s[i]=s[i-1]

for k,v in l:
    ans=s[v]-s[k-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def check(i):
    num=int(i**0.5)
    if i==1:return 0
    if i==2:return 1
    for j in range(2,num+1):
        if i%j==0:break

    else:return 1
    return 0
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]

for l,r in lr:
    cnt=0
    for i in range(l,r+1,2):
        if check(i):
            next_num=int((i+1)//2)
            cnt+=check(next_num)
    print(cnt)

Fixed submission:
q=int(input())
l=[list(map(int,input().split())) for i in range(q)]

def jud(i):
    #iの素数判定
    num=int(i**0.5)+1
    for k in range(2,num):
        if i%k==0:
            return 0
    return 1

s=[0]*(10**5+1)
for i in range(2,10**5+1):
    if i%2==0:
        s[i]=s[i-1]
    else:
        if jud(i)*jud((i+1)//2)==1:
            s[i]=s[i-1]+1
        else:
            s[i]=s[i-1]

for k,v in l:
    ans=s[v]-s[k-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]

for l,r in lr:
    cnt=0
    for i in range(l,r+1,2):
        num=int(i**0.5)
        like_num=(i+1)//2
        if like_num==1:continue
        num2=int(like_num**0.5)
        for j in range(3,num+1,2):
            if i%j==0:break
        else:
            for j in range(2,num2+1):
                if like_num!=2 and like_num%j==0:break
            else:
                cnt+=1
                #print(i,cnt)
    print(cnt)

Fixed submission:
q=int(input())
l=[list(map(int,input().split())) for i in range(q)]

def jud(i):
    #iの素数判定
    num=int(i**0.5)+1
    for k in range(2,num):
        if i%k==0:
            return 0
    return 1

s=[0]*(10**5+1)
for i in range(2,10**5+1):
    if i%2==0:
        s[i]=s[i-1]
    else:
        if jud(i)*jud((i+1)//2)==1:
            s[i]=s[i-1]+1
        else:
            s[i]=s[i-1]

for k,v in l:
    ans=s[v]-s[k-1]
    print(ans)