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

def pri_num(n):
    for i in range(2,math.floor(n**0.5)+1):
        if n%i == 0:
            return 0
    return 1

def like_2017(n1):
    f2 = pri_num((n1+1)//2)
    if f2 == 0:
        return 0
    f1 = pri_num(n1)
    return f1*f2

Q = int(input())
memo = [-1]*(10**5+1)
for _ in range(Q):
    l,r= map(int,input().split())
    cnt = 0
    for i in range(l,r+1,2):
        if i%3 == 0 and i!=3:
            continue
        if i == 1:
            continue
        else:
            if memo[i] == -1:
                memo[i]= like_2017(i)
            cnt += memo[i]
    print(cnt)
    


Fixed submission:
memo =[1]*(10**5+1)
memo[0]=0
memo[1]=0
for i in range(2,len(memo)):
    if memo[i]==0:
        continue
    else:
        for j in range(i*2,len(memo),i):
            memo[j]=0
memo_like2017 = [0]*(10**5+1)
for i in range(3,len(memo),2):
    if memo[i]==1 and memo[(i+1)//2] ==1:
        memo_like2017[i]=1
sum_memo=[0]*(10**5+1)
for i in range(1,len(memo)):
    sum_memo[i] = sum_memo[i-1]+memo_like2017[i]

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

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

def pri_num(n):
    for i in range(2,math.floor(n**0.5)+1):
        if n%i == 0:
            return 0
    return 1

def like_2017(n1):
    f2 = pri_num((n1+1)//2)
    if f2 == 0:
        return 0
    f1 = pri_num(n1)
    return f1*f2

Q = int(input())
memo = [-1]*(10**5+1)
for _ in range(Q):
    l,r= map(int,input().split())
    cnt = 0
    for i in range(l,r+1,2):
        if i == 1:
            continue
        else:
            if memo[i] == -1:
                memo[i]= like_2017(i)
            cnt += memo[i]
    print(cnt)
    


Fixed submission:
memo =[1]*(10**5+1)
memo[0]=0
memo[1]=0
for i in range(2,len(memo)):
    if memo[i]==0:
        continue
    else:
        for j in range(i*2,len(memo),i):
            memo[j]=0
memo_like2017 = [0]*(10**5+1)
for i in range(3,len(memo),2):
    if memo[i]==1 and memo[(i+1)//2] ==1:
        memo_like2017[i]=1
sum_memo=[0]*(10**5+1)
for i in range(1,len(memo)):
    sum_memo[i] = sum_memo[i-1]+memo_like2017[i]

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

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

def pri_num(n):
    for i in range(2,math.floor(n**0.5)+1):
        if n%i == 0:
            return 0
    return 1

def like_2017(n1):
    f2 = pri_num((n1+1)//2)
    if f2 == 0:
        return 0
    f1 = pri_num(n1)
    return f1*f2

Q = int(input())
memo = [-1]*(10**5+1)
for _ in range(Q):
    l,r= map(int,input().split())
    cnt = 0
    for i in range(l,r+1,2):
        if i == 1:
            continue
        else:
            if memo[i] == -1:
                memo[i]= like_2017(i)
            cnt += memo[i]
    print(cnt)
    


Fixed submission:
memo =[1]*(10**5+1)
memo[0]=0
memo[1]=0
for i in range(2,len(memo)):
    if memo[i]==0:
        continue
    else:
        for j in range(i*2,len(memo),i):
            memo[j]=0
memo_like2017 = [0]*(10**5+1)
for i in range(3,len(memo),2):
    if memo[i]==1 and memo[(i+1)//2] ==1:
        memo_like2017[i]=1
sum_memo=[0]*(10**5+1)
for i in range(1,len(memo)):
    sum_memo[i] = sum_memo[i-1]+memo_like2017[i]

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

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

def pri_num(n):
    for i in range(2,math.floor(n**0.5)+1):
        if n%i == 0:
            return 0
    return 1

def like_2017(n1):
    f1 = pri_num(n1)
    f2 = pri_num((n1+1)//2)
    return f1*f2

Q = int(input())
memo = [-1]*(10**5+1)
for _ in range(Q):
    l,r= map(int,input().split())
    cnt = 0
    for i in range(l,r+1,2):
        if i == 1:
            continue
        else:
            if memo[i] == -1:
                memo[i]= like_2017(i)
            cnt += memo[i]
    print(cnt)
    


Fixed submission:
memo =[1]*(10**5+1)
memo[0]=0
memo[1]=0
for i in range(2,len(memo)):
    if memo[i]==0:
        continue
    else:
        for j in range(i*2,len(memo),i):
            memo[j]=0
memo_like2017 = [0]*(10**5+1)
for i in range(3,len(memo),2):
    if memo[i]==1 and memo[(i+1)//2] ==1:
        memo_like2017[i]=1
sum_memo=[0]*(10**5+1)
for i in range(1,len(memo)):
    sum_memo[i] = sum_memo[i-1]+memo_like2017[i]

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

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

def pri_num(n):
    for i in range(2,math.floor(n**0.5)+1):
        if n%i == 0:
            return 0
    return 1

def like_2017(n1):
    f1 = pri_num(n1)
    f2 = pri_num((n1+1)//2)
    return f1*f2

Q = int(input())
memo = [-1]*(10**5+1)
for _ in range(Q):
    l,r= map(int,input().split())
    cnt = 0
    for i in range(l,r+1,2):
        if i == 1:
            continue
        else:
            if memo[i] == -1:
                memo[i]= like_2017(i)
            cnt += memo[i]
    print(cnt)
    


Fixed submission:
memo =[1]*(10**5+1)
memo[0]=0
memo[1]=0
for i in range(2,len(memo)):
    if memo[i]==0:
        continue
    else:
        for j in range(i*2,len(memo),i):
            memo[j]=0
memo_like2017 = [0]*(10**5+1)
for i in range(3,len(memo),2):
    if memo[i]==1 and memo[(i+1)//2] ==1:
        memo_like2017[i]=1
sum_memo=[0]*(10**5+1)
for i in range(1,len(memo)):
    sum_memo[i] = sum_memo[i-1]+memo_like2017[i]

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