Buggy python submission (verdict: Runtime Error):
max_num = 10**5+5
eratos_thenes_sieve = [0,0] + [1]*maxnum
n = 2 #素数
while n*n <= max_num:
  if eratos_thenes_sieve[n]:#
    for i in range(2*n, max_num, n):
      eratos_thenes_sieve[i] = 0
  n += 1
  
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
  if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i+1)//2]:
    isLike2017[i] = 1
  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
  
  
q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(cumulativeSums[r+1] - cumulativeSums[l])

Fixed submission:
max_num = 10**5+5
eratos_thenes_sieve = [0,0] + [1]*max_num
n = 2 #素数
while n*n <= max_num:
  if eratos_thenes_sieve[n]:#
    for i in range(2*n, max_num, n):
      eratos_thenes_sieve[i] = 0
  n += 1
  
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
  if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i+1)//2]:
    isLike2017[i] = 1
  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
  
  
q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(cumulativeSums[r+1] - cumulativeSums[l])

Buggy python submission (verdict: Time Limit Exceeded):
finished = [False] * 10**5
isPN = [False] * 10**5
def isPrimeNumber(num):
  if finished[num]:
    return isPN[num]
  
  if num == 1:
    return False
  pn = 2
  while pn * pn <= num:
    if num % pn == 0:
      finished[num] = True
      isPN[num] = False
      return isPN[num]
    pn += 1
  
  
  finished[num] = True
  isPN[num] = True
  return isPN[num]

n = int(input())

l = [0] * n
r = [0] * n
for i in range(n):
  l[i], r[i] = map(int, input().split())
  
  
for i in range(n):
  ans = 0
  for j in range(l[i], r[i]+1, 2):
    if isPrimeNumber(j) and isPrimeNumber(int((j+1)/2)):
      ans += 1
      
  print(ans)

Fixed submission:
max_num = 10**5+5
eratos_thenes_sieve = [0,0] + [1]*max_num
n = 2 #素数
while n*n <= max_num:
  if eratos_thenes_sieve[n]:#
    for i in range(2*n, max_num, n):
      eratos_thenes_sieve[i] = 0
  n += 1
  
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
  if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i+1)//2]:
    isLike2017[i] = 1
  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
  
  
q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(cumulativeSums[r+1] - cumulativeSums[l])

Buggy python submission (verdict: Runtime Error):
finished = [False] * 10**5
isPN = [False] * 10**5
def isPrimeNumber(num):
  if finished[num]:
    return isPN[num]
  
  if num == 1:
    return False
  pn = 2
  while pn * pn <= num:
    if num % pn == 0:
      finished[num] = True
      isPN[num] = False
      return isPN[num]
    pn += 1
  
  
  finished[num] = True
  isPN[num] = True
  return isPN[num]

n = int(input())

l = [0] * n
r = [0] * n
for i in range(n):
  l[i], r[i] = map(int, input().split())
  
  
for i in range(n):
  ans = 0
  for j in range(l[i], r[i]+1, 2):
    if isPrimeNumber(j) and isPrimeNumber((j+1)/2):
      ans += 1
      
  print(ans)

Fixed submission:
max_num = 10**5+5
eratos_thenes_sieve = [0,0] + [1]*max_num
n = 2 #素数
while n*n <= max_num:
  if eratos_thenes_sieve[n]:#
    for i in range(2*n, max_num, n):
      eratos_thenes_sieve[i] = 0
  n += 1
  
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
  if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i+1)//2]:
    isLike2017[i] = 1
  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
  
  
q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(cumulativeSums[r+1] - cumulativeSums[l])

Buggy python submission (verdict: Time Limit Exceeded):
def isPrimeNumber(num):
  if num == 1:
    return False
  pn = 2
  while pn * pn <= num:
    if num % pn == 0:
      return False
    pn += 1
  return True

n = int(input())

l = [0] * n
r = [0] * n
for i in range(n):
  l[i], r[i] = map(int, input().split())
  
  
for i in range(n):
  ans = 0
  for j in range(l[i], r[i]+1, 2):
    if isPrimeNumber(j) and isPrimeNumber((j+1)/2):
      ans += 1
      
  print(ans)

Fixed submission:
max_num = 10**5+5
eratos_thenes_sieve = [0,0] + [1]*max_num
n = 2 #素数
while n*n <= max_num:
  if eratos_thenes_sieve[n]:#
    for i in range(2*n, max_num, n):
      eratos_thenes_sieve[i] = 0
  n += 1
  
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
  if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i+1)//2]:
    isLike2017[i] = 1
  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
  
  
q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(cumulativeSums[r+1] - cumulativeSums[l])