Buggy python submission (verdict: Time Limit Exceeded):
def make_divisors(n):  
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
def islike2017(i):
  if i%2==0:
    return False
  if len(make_divisors(i))==2:
    if len(make_divisors(((i+1)//2)))==2:
      return True
  return False
def main():
  q=int(input())
  lr=[list(map(int,input().split())) for _ in range(q)]
  all=[lri[0] for lri in lr]
  all[q:q]=[lri[1] for lri in lr]
  all.sort()
  d={}
  c=0
  d[all[0]]=c
  for i in range(2*q-1):
    for j in range(all[i],all[i+1]):
      if islike2017(j):
        c+=1
    d[all[i+1]]=c
  for l,r in lr:
    a=d[r]-d[l]
    a+=1 if islike2017(r) else 0
    print(a)
  
if __name__=='__main__':
  main()


Fixed submission:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
a=[]
for i in range(3,10**5):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
for lri in lr:
  print(len([ai for ai in a if ai>=lri[0] and ai<=lri[1]]))

Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
a=[]
for i in range(3,10**5):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
for lri in lr:
  print(len([ai for ai in a if ai>=lri[0] and ai<=lri[1]]))

Fixed submission:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
a=[]
for i in range(3,10**5):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
for lri in lr:
  print(len([ai for ai in a if ai>=lri[0] and ai<=lri[1]]))

Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())
lr=[list(map(int,(str(_)+' '+input()).split())) for _ in range(q)]
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
lr.sort(key=lambda x:x[1])
ans=[]
l_=lr[0][1]
r_=lr[0][2]
a=[]
for i in range(l_,r_+1):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
ans.append([lr[0][0],a])
for i in range(1,q):
  r_=lr[i][2]
  a=[ai for ai in a if ai<l_]
  l_=lr[i][1] if len(a)==0 else a[-1]
  for j in range(l_,r_+1):
    if is_prime(j) and is_prime((j+1)//2):
      a.append(j)
  ans.append([lr[i][0],a])
ans.sort(key=lambda x:x[0])
for i in range(q):
  print(len(ans[i][1]))


Fixed submission:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
a=[]
for i in range(3,10**5):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
for lri in lr:
  print(len([ai for ai in a if ai>=lri[0] and ai<=lri[1]]))

Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())
lr=[list(map(int,(str(_)+' '+input()).split())) for _ in range(q)]
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
lr.sort(key=lambda x:x[1])
ans=[]
l_=lr[0][1]
r_=lr[0][2]
a=[]
for i in range(l_,r_+1):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
ans.append([lr[0][0],a])
for i in range(1,q):
  r_=lr[i][2]
  a=[ai for ai in a if ai<l_]
  l_=lr[i][1] if len(a)==0 else a[-1]
  for j in range(l_,r_+1):
    if is_prime(j) and is_prime((j+1)//2):
      a.append(j)
  ans.append([lr[i][0],a])
ans.sort(key=lambda x:x[0])
for i in range(q):
  print(len(ans[i][1]))


Fixed submission:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
a=[]
for i in range(3,10**5):
  if is_prime(i) and is_prime((i+1)//2):
    a.append(i)
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
for lri in lr:
  print(len([ai for ai in a if ai>=lri[0] and ai<=lri[1]]))