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

N = 100000
like_number = [3]
prime_number = [2]
for i in range(3, N, 2):
   flag = 0
#   for j in range(3, int(i**0.5)+1, 2):
   for j in prime_number:
      if j > int(i**0.5)+1:
         break
      elif i%j == 0:
         flag = 1
         break
   if flag == 0:
      prime_number.append(i)
      if ((i+1)/2)%2 == 1:
         if (i+1)/2 in prime_number:
            like_number.append(i)
         

for i in range(Q):
   count = 0
   for j in like_number:
      if lr[i][1] >= j:
         if lr[i][0] <= j:
            count = count + 1
      else:
         break
   print(count)


Fixed submission:
def main():
    Q = int(input())
    L = [0 for _ in range(Q)]
    R = [0 for _ in range(Q)]
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    N = 100000
    sosu = [1 for _ in range(N)]
    sosu[0] = 0
    for i in range(1,int(N**0.5)):
        k = i+1
        if sosu[i] == 1:
            j = k + k
            while j <= N:
                sosu[j-1] = 0
                j = j+k
    like = [0 for _ in range(N)]
    for i in range(2, N, 2):
        if sosu[i]==1 and sosu[(i+2)//2-1]==1:
            like[i] = 1
    like_wa = [0 for _ in range(N+1)]
    for i in range(N):
        like_wa[i+1] = like_wa[i] + like[i]

    for i in range(Q):
        print(like_wa[R[i]] - like_wa[L[i]-1])

if __name__ == '__main__':
    main()

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

N = 100000
like_number = [3]
prime_number = [2]
for i in range(3, N, 2):
   flag = 0
   for j in range(3, int(i**0.5)+1, 2):
      if i%j == 0:
         flag = 1
         break
   if flag == 0:
      prime_number.append(i)
      if ((i+1)/2)%2 == 1:
         if (i+1)/2 in prime_number:
            like_number.append(i)
         

for i in range(Q):
   count = 0
   for j in like_number:
      if lr[i][1] >= j:
         if lr[i][0] <= j:
            count = count + 1
      else:
         break
   print(count)


Fixed submission:
def main():
    Q = int(input())
    L = [0 for _ in range(Q)]
    R = [0 for _ in range(Q)]
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    N = 100000
    sosu = [1 for _ in range(N)]
    sosu[0] = 0
    for i in range(1,int(N**0.5)):
        k = i+1
        if sosu[i] == 1:
            j = k + k
            while j <= N:
                sosu[j-1] = 0
                j = j+k
    like = [0 for _ in range(N)]
    for i in range(2, N, 2):
        if sosu[i]==1 and sosu[(i+2)//2-1]==1:
            like[i] = 1
    like_wa = [0 for _ in range(N+1)]
    for i in range(N):
        like_wa[i+1] = like_wa[i] + like[i]

    for i in range(Q):
        print(like_wa[R[i]] - like_wa[L[i]-1])

if __name__ == '__main__':
    main()

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

N = 100000
like_number = [3]
prime_number = [2]
for i in range(3, N, 2):
   flag = 0
   for j in range(3, int(i**0.5)+1, 2):
      if i%j == 0:
         flag = 1
         break
   if flag == 0:
      prime_number.append(i)
      if ((i+1)/2)%2 == 1:
         if (i+1)/2 in prime_number:
            like_number.append(i)
         

for i in range(Q):
   count = 0
   for j in range(lr[i][0], lr[i][1]+1):
      if j in like_number:
         count = count + 1
   print(count)


Fixed submission:
def main():
    Q = int(input())
    L = [0 for _ in range(Q)]
    R = [0 for _ in range(Q)]
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    N = 100000
    sosu = [1 for _ in range(N)]
    sosu[0] = 0
    for i in range(1,int(N**0.5)):
        k = i+1
        if sosu[i] == 1:
            j = k + k
            while j <= N:
                sosu[j-1] = 0
                j = j+k
    like = [0 for _ in range(N)]
    for i in range(2, N, 2):
        if sosu[i]==1 and sosu[(i+2)//2-1]==1:
            like[i] = 1
    like_wa = [0 for _ in range(N+1)]
    for i in range(N):
        like_wa[i+1] = like_wa[i] + like[i]

    for i in range(Q):
        print(like_wa[R[i]] - like_wa[L[i]-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def Prime(x):
   if x == 2:
      return 1
   elif (x<2) or (x%2==0):
      return 0
   else:
      i = 3
      while i <= x**0.5:
         if x%i == 0:
            return 0
         i = i + 2
      return 1

Q = int(input())
l_r = []
for i in range(Q):
   l_r.append(list(map(int, input().split())))

like_Number = []

X_mem = []
X_mem_non = []
for l_r in l_r:
   l = l_r[0]
   r = l_r[1]
   count = 0
   for x in range(l, r+1):
      if x%2 == 1: # 奇数だけ
         if x in X_mem:
            count = count + 1
         elif (x in X_mem_non) == False:
            if Prime(x) == 1:
               if Prime((x+1)/2) == 1:
                  X_mem.append(x)
                  count = count + 1
               else:
                  X_mem_non.append(x)
            else:
               X_mem_non.append(x)

   like_Number.append(count)

for i in range(Q):
   print(like_Number[i])
         


Fixed submission:
def main():
    Q = int(input())
    L = [0 for _ in range(Q)]
    R = [0 for _ in range(Q)]
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    N = 100000
    sosu = [1 for _ in range(N)]
    sosu[0] = 0
    for i in range(1,int(N**0.5)):
        k = i+1
        if sosu[i] == 1:
            j = k + k
            while j <= N:
                sosu[j-1] = 0
                j = j+k
    like = [0 for _ in range(N)]
    for i in range(2, N, 2):
        if sosu[i]==1 and sosu[(i+2)//2-1]==1:
            like[i] = 1
    like_wa = [0 for _ in range(N+1)]
    for i in range(N):
        like_wa[i+1] = like_wa[i] + like[i]

    for i in range(Q):
        print(like_wa[R[i]] - like_wa[L[i]-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def Prime(x):
   if x == 2:
      return 1
   elif (x<2) or (x%2==0):
      return 0
   else:
      i = 3
      while i <= x**0.5:
         if x%i == 0:
            return 0
         i = i + 2
      return 1

Q = int(input())
l_r = []
for i in range(Q):
   l_r.append(list(map(int, input().split())))

like_Number = []

for l_r in l_r:
   l = l_r[0]
   r = l_r[1]
   count = 0
   for x in range(l, r+1):
      if x%2 == 1: # 奇数だけ
         if Prime(x) == 1:
            if Prime((x+1)/2) == 1:
               count = count + 1
   like_Number.append(count)

for i in range(Q):
   print(like_Number[i])
         


Fixed submission:
def main():
    Q = int(input())
    L = [0 for _ in range(Q)]
    R = [0 for _ in range(Q)]
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    N = 100000
    sosu = [1 for _ in range(N)]
    sosu[0] = 0
    for i in range(1,int(N**0.5)):
        k = i+1
        if sosu[i] == 1:
            j = k + k
            while j <= N:
                sosu[j-1] = 0
                j = j+k
    like = [0 for _ in range(N)]
    for i in range(2, N, 2):
        if sosu[i]==1 and sosu[(i+2)//2-1]==1:
            like[i] = 1
    like_wa = [0 for _ in range(N+1)]
    for i in range(N):
        like_wa[i+1] = like_wa[i] + like[i]

    for i in range(Q):
        print(like_wa[R[i]] - like_wa[L[i]-1])

if __name__ == '__main__':
    main()