Buggy python submission (verdict: Time Limit Exceeded):
primes = [[True]*100000][0]
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [[False]*100000][0]

for i in range(3, 100000, 2):
  if primes[i] == False:
    continue
  if primes[(i+1)//2] == True:
    c[i] = True

q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(sum(c[:ran[i][1]+1])-sum(c[:ran[i][0]]))


Fixed submission:
primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
q = int(input())


def isPrime(q):
  if q == 2:
    return True
  if q%2 == 0 or q == 1:
    return False
  j = 3
  while j <= math.sqrt(q):
    if q%j == 0:
      return False
    j += 2
  return True

C = []
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))

primes = []
for i in range(1, 100000):
  if isPrime(i):
    primes.append(i)

for i in range(q):
  count = 0
  for j in primes:
    if j < ran[i][0]:
      continue
    if j > ran[i][1] :
      break
    if ((j+1)//2) in primes:
      count += 1
  C.append(count)

for i in range(q):
  print(C[i])


Fixed submission:
primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
q = int(input())


def isPrime(q):
  if q == 2:
    return True
  if q%2 == 0 or q == 1:
    return False
  j = 3
  while j <= math.sqrt(q):
    if q%j == 0:
      return False
    j += 2
  return True

primes = []
for i in range(1, 100000):
  if isPrime(i):
    primes.append(i)

C = []
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
#print(ran)

for i in range(q):
  if ran[i][0] % 2 == 0:
    j = ran[i][0]+1
  else:
    j = ran[i][0]
  count = 0
  while j <= ran[i][1] :
    if j in primes and ((j+1)//2) in primes:
      count += 1
    j += 2
  C.append(count)

for i in range(q):
  print(C[i])


Fixed submission:
primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
q = int(input())

Carm = [561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973, 75361]

def isPrime(q):
  if q == 2:
    return True
  if q == 1 or q in Carm:
    return False
  return pow(2, q-1, q) == 1


C = []
for i in range(q):
  ran = list(map(int, input().split()))
  if ran[0] % 2 == 0:
    j = ran[0]+1
  else:
    j = ran[0]
  count = 0
  while j <= ran[1] :
    if isPrime(j) and isPrime((j+1)//2):
      count += 1
    j += 2
  C.append(count)

for i in range(q):
  print(C[i])


Fixed submission:
primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
q = int(input())

def isPrime(n):
  if n == 2:
    return True
  if n % 2==0 or n == 1:
    return False
  j = 3
  while j <= math.sqrt(n):
    if n % j == 0:
      return False
    j += 2
  return True

primes = []
for i in range(100000):
  if isPrime(i):
    primes.append(i)


C = []
for i in range(q):
  ran = list(map(int, input().split()))
  for i in range(q):
    if ran[0] % 2 == 0:
        j = ran[0]+1
    j = ran[0]
    count = 0
    while j <= ran[1] :
      if j in primes and (j+1)//2 in primes:
        count += 1
      j += 2
  C.append(count)

for i in range(q):
  print(C[i])


Fixed submission:
primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
q = int(input())

def isPrime(n):
  if n == 2:
    return True
  if n % 2==0 or n == 1:
    return False
  j = 3
  while j <= math.sqrt(n):
    if n % j == 0:
      return False
    j += 2
  return True

C = []
for i in range(q):
  ran = list(map(int, input().split()))
  for i in range(q):
    if ran[0] % 2 == 0:
        j = ran[0]+1
    j = ran[0]
    count = 0
    while j <= ran[1] :
      if isPrime(j) and isPrime((j+1)//2):
        count += 1
      j += 2
  C.append(count)

for i in range(q):
  print(C[i])


Fixed submission:
primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])