qyliang/CodeNanoFix huggingface dataset:
Buggy code:
q = int(input())
p = [False]*(10**5)
c = [0]*(10**5)
temp = [True]*(N+1)
temp[0] = False
temp[1] = False
for i in range(2, 10**5):
  c[i] = c[i-1]
  if temp[i]:
    temp[2*i::i] = [False]*(len(temp[i+i::i]))
    if temp[(i+1)//2] and i%2:
      c[i] += 1

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

Fixed code:
q = int(input())
p = [False]*(10**5)
c = [0]*(10**5)
temp = [True]*(10**5)
temp[0] = False
temp[1] = False
for i in range(2, 10**5):
  c[i] = c[i-1]
  if temp[i]:
    temp[2*i::i] = [False]*(len(temp[i+i::i]))
    if temp[(i+1)//2] and i%2:
      c[i] += 1

for _ in range(q):
  l, r = map(int, input().split())
  print(c[r] - c[l-1])
Buggy code:
import sys
import bisect
import math
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

mc = max(l)[1]
mc_sqrt = math.sqrt(mc)

sys.exit()

prime = [i for i in range(2, mc + 1)]
c = 0
while True:
    if c >= len(prime):
        break
    t = prime[c]
    prime = [v for v in prime if v == t or v % t != 0]
    c = c + 1
    if c >= mc_sqrt:
        break
        
cum = [0 for i in range(mc + 1)]
for i in range(len(cum)):
    prime_index = bisect.bisect_left(prime, i)
    
    n2 = (i + 1) / 2
    prime_index2 = bisect.bisect_left(prime, n2)
    if len(prime) > prime_index and len(prime) > prime_index2 and prime[prime_index] == i and prime[prime_index2] == n2:
        cum[i] = cum[i - 1] + 1
    else:
        if i - 1 < 0:
            cum[i] = 0
        else:
            cum[i] = cum[i - 1]
        
for x, y in l:
    p = cum[x] - cum[x - 1]
    if x != y:
        p += cum[y] - cum[x]
    print(p)


Fixed code:
import sys
import bisect
import math
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

mc = 0
for v in l:
    mc = max(mc, v[1])
mc_sqrt = math.sqrt(mc)

prime = [i for i in range(2, mc + 1)]
c = 0
while True:
    if c >= len(prime):
        break
    t = prime[c]
    prime = [v for v in prime if v == t or v % t != 0]
    c = c + 1
    if c >= mc_sqrt:
        break
        
cum = [0 for i in range(mc + 1)]
for i in range(len(cum)):
    prime_index = bisect.bisect_left(prime, i)
    
    n2 = (i + 1) / 2
    prime_index2 = bisect.bisect_left(prime, n2)
    if len(prime) > prime_index and len(prime) > prime_index2 and prime[prime_index] == i and prime[prime_index2] == n2:
        cum[i] = cum[i - 1] + 1
    else:
        if i - 1 < 0:
            cum[i] = 0
        else:
            cum[i] = cum[i - 1]

for t in l:
    x, y = t[0], t[1]
    p = 0
    if 0 <= x - 1:
        p = cum[x] - cum[x - 1]
    if x != y:
        p += cum[y] - cum[x]
    print(p)
Buggy code:
def prime(n):
  if n==1:
    return False
  elif n==2:
    return True
  else:
    for i in range(2,int((n)**(1/2))+1):
      if n%i==0:
        return False
    return True
list=[True]*100001
for i in range(1,100001):
  if not prime(i):
    list[i]=False
list1=[0]
count=0
for i in range(1,100001):
  if i%2==1:
    if list[i] and list[(i+1)//2]:
      count+=1
  list1.append(count)
n=int(input())
for i in range(n):
  a,b=map(int,input().split())
  print(list1[b]-list1[a])

Fixed code:
def prime(n):
  if n==1:
    return False
  elif n==2:
    return True
  else:
    for i in range(2,int((n)**(1/2))+1):
      if n%i==0:
        return False
    return True
list=[True]*100001
for i in range(1,100001):
  if not prime(i):
    list[i]=False
list1=[0]
count=0
for i in range(1,100001):
  if i%2==1:
    if list[i] and list[(i+1)//2]:
      count+=1
  list1.append(count)
n=int(input())
for i in range(n):
  a,b=map(int,input().split())
  print(list1[b]-list1[a-1])
Buggy code:
def sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)]
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

pl=sieve_of_eratosthenes(100000)

p_list = [0 for i in range(100001)]

for p in pl:
    p_list[p]+=1

ps_list = [0]
ps = 0

for i in range(1,100001):
    ps+=p_list[i]
    ps_list.append(ps)

Q = int(input())

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

Fixed code:
def sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)]
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

pl=sieve_of_eratosthenes(100000)

p_list = [0 for i in range(100001)]

for p in pl:
    if 2*p-1<=100000:
        p_list[2*p-1]+=1
    p_list[p]+=1


ps_list = [0]
ps = 0

for i in range(1,100001):
    if p_list[i]>=2:
        ps+=1
    ps_list.append(ps)



Q = int(input())

for i in range(Q):
    l,r = list(map(int,input().split()))
    print(ps_list[r]-ps_list[l-1])
Buggy code:
p=[True for _ in range(10**5)]
max_loop=int((10**5)**0.5)
for j in range(2,max_loop):
    if(p[j]==True):
        i=j*2
        while True:
            if(i>=10**5):
                break
            p[i]=False
            i+=j




ans=[0 for _ in range(10**5)]
for j in range(10**5):
    if(p[j] and p[(j+1)//2]):
        ans[j]+=1
    ans[j]=ans[j]+ans[j-1]

N=int(input())
for j in range(N):
    x,y=map(int,input().split())
    print(ans[y]-ans[x-1])

Fixed code:
p=[True for _ in range(10**5)]
max_loop=int((10**5)**0.5)
for j in range(2,max_loop):
    if(p[j]==True):
        i=j*2
        while True:
            if(i>=10**5):
                break
            p[i]=False
            i+=j

ans=[0 for _ in range(10**5)]
for j in range(2,10**5):
    if(j%2==1 and p[j] and p[(j+1)//2]):
        ans[j]+=1
    ans[j]=ans[j]+ans[j-1]

N=int(input())
for j in range(N):
    x,y=map(int,input().split())
    print(ans[y]-ans[x-1])
Buggy code:

def isprime(x):
  if x < 2: return False
  for d in range(2, int(x**0.5)+1):
    if x % d == p: return False
  return True

isp = list(map(isprime, range(100001)))
w = [0]*100001
for i in range(100001):
  if i > 2 and isp[i] and isp[(i + 1)//2]:
    w[i] = 1

for i in range(1,100001):
  w[i] += w[i-1]

Q = int(input())
for i in range(Q):
  L,R = map(int, input().split())
  print(w[R] - w[L-1])

Fixed code:
def isprime(x):
  if x < 2: return False
  for d in range(2, int(x**0.5)+1):
    if x % d == 0: return False
  return True

isp = list(map(isprime, range(100001)))
w = [0]*100001
for i in range(100001):
  if i > 2 and isp[i] and isp[(i + 1)//2]:
    w[i] = 1

for i in range(1,100001):
  w[i] += w[i-1]

Q = int(input())
for i in range(Q):
  L,R = map(int, input().split())
  print(w[R] - w[L-1])
Buggy code:
Q = int(input())

lim = 10**5+10
p = [True]*lim
p[0] = False
p[1] = False
for i in range(2, int(lim**0.5)+1):
    for j in range(i*2, 10**5+1, i):
        p[j] = False

y = [0]*lim
for i in range(3, lim, 2):
    y[i] = y[i-2]
    if p[i] and p[(i+1)//2]:
        y[i] += 1

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

Fixed code:
Q = int(input())

lim = 10**5+10
p = [True]*lim
p[0] = False
p[1] = False
for i in range(2, int(lim**0.5)+1):
    for j in range(i*2, 10**5+1, i):
        p[j] = False

y = [0]*lim
for i in range(3, lim, 2):
    y[i] = y[i-2]
    if p[i] and p[(i+1)//2]:
        y[i] += 1
    y[i-1] = y[i-2]

for _ in range(Q):
    l, r = map(int, input().split())
    print(y[r]-y[l-1])
Buggy code:
def era(M):
    p = [1] * M
    p[0] = p[1] = 0
    for x in range(2, int(~-M**.5) + 1):
        if p[x]:
            for y in range(x*x, M, x):
                p[y] = 0
    return p
INF = 10**5 + 1
E = erat(INF)
Q = [0] * INF
from itertools import*
for i in range(INF):
    q[i] = i%2 * p[i] * p[-~i//2]
*a, = accumulate([0] + q)
for _ in [None] * int(input()):
    l, r = map(int, input().split())
    print(a[-~r] - a[l])

Fixed code:
def erat(M):
    p = [1] * M
    p[0] = p[1] = 0
    for x in range(2, int((M - 1)**.5) + 1):
        if p[x]:
            for y in range(x*x, M, x):
                p[y] = 0
    return p
INF = 10**5 + 1
p = erat(INF)
q = [0] * INF
from itertools import*
for i in range(INF):
    q[i] = i%2 * p[i] * p[-~i//2]
*a, = accumulate([0] + q)
for _ in [None] * int(input()):
    l, r = map(int, input().split())
    print(a[-~r] - a[l])
Buggy code:
q = int(input())
a = [list(int(i) for i in input().split()) for i in range(q)]
MAX = 10**5
is_prime = [1]*MAX
for i in range(2, MAX):
    if not is_prime[i]:
        continue
    for j in range(i*2, MAX, i):
        is_prime[j] = 0
s = [0]*MAX
for i in range(3,MAX):
    s[i] = s[i-1] + 1 if is_prime[i] and is_prime[(i+1)//2]
for i in range(q):
    l,r = a[i]
    print(s[r]-s[l-1])

Fixed code:
q = int(input())
a = [list(int(i) for i in input().split()) for i in range(q)]
MAX = 10**5
is_prime = [1]*MAX
for i in range(2, MAX):
    if not is_prime[i]:
        continue
    for j in range(i*2, MAX, i):
        is_prime[j] = 0
s = [0]*MAX
for i in range(3,MAX):
    s[i] = s[i-1] + 1 if is_prime[i] and is_prime[(i+1)//2] else s[i-1]
for i in range(q):
    l,r = a[i]
    print(s[r]-s[l-1])
Buggy code:
import bisect
Q = int(input())

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(n**0.5)+1):
        if n % k == 0:
            return 0
    return n

prime_numbers = [is_prime(i) for i in range(2, 10**5 + 1) if is_prime(i) != 0]
# print(prime_numbers)
same = [0]*(10**5 + 1)
for n in prime_numbers:
    # print(n)
    if (n+1) // 2 in prime_numbers:
        same[n] += 1
# print(same)
# print(same[:20])

for i in range(10**5):
    same[i+1] += same[i]
# print(same[:20])
# print(same[3], same[5])
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    N = same[r] - same[l]
    if same[l] != same[l-1] or same[r] != same[r-1]:
        N += 1
        if l == r:
            N += 1
    ans.append(N)

print(*ans, sep='\n')


Fixed code:
import bisect
Q = int(input())

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(n**0.5)+1):
        if n % k == 0:
            return 0
    return n

prime_numbers = [is_prime(i) for i in range(2, 10**5 + 1) if is_prime(i) != 0]
# print(prime_numbers)
same = [0]*(10**5 + 1)
for n in prime_numbers:
    # print(n)
    if (n+1) // 2 in prime_numbers:
        same[n] += 1
# print(same)
# print(same[:20])

for i in range(10**5):
    same[i+1] += same[i]
# print(same[:20])
# print(same[3], same[5])
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    N = same[r] - same[l-1]
    # if same[l] != same[l-1] or same[r] != same[r-1]:
    #     N += 1
    #     if l == r:
    #         N += 1
    ans.append(N)

print(*ans, sep='\n')
Buggy code:
import math
Q = int(input())

def sosuu(x):
  if x == 1:
    return False
  else:
    for i in range(1,int(math.sqrt(x))+1):
      if x % (i+1) == 0:
        return False
    return True

table=[0]*50001
for i in range(1,50001):
  if i%2==1 and sosuu((i+1)//2) and sosuu(i):
    table[i]=table[i-1] + 1
  else:
    table[i]=table[i-1]
#print(table[0:10])
ans=[0]*Q
for i in range(Q):
  l,r=map(int,input().split())
  ans[i]=table[r] - table[l-1]
  
for i in range(Q):
  print(ans[i])
  

Fixed code:
import math
Q = int(input())

def sosuu(x):
  if x == 1:
    return False
  else:
    for i in range(1,int(math.sqrt(x))):
      if x % (i+1) == 0:
        return False
    return True

table=[0]*100001
for i in range(1,100001):
  if i%2==1 and sosuu(int((i+1)/2)) and sosuu(i):
    table[i]=table[i-1] + 1
  else:
    table[i]=table[i-1]
#print(table[0:10])
ans=[0]*Q
for i in range(Q):
  l,r=map(int,input().split())
  ans[i]=table[r] - table[l-1]
  
for i in range(Q):
  print(ans[i])
Buggy code:
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(100000-1):
  if primes[i] and primes[(i+1)//2] == True:
    c[i+1] = c[i]+1
  else:
    c[i+1] = c[i]

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])


Fixed code:
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 code:
from math import floor,sqrt

def eratosthenes(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, floor(sqrt(n))+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table
  
s = set(eratosthenes(10**5))
l = [0]*(10**5 + 1)
count = 0

for i in range(10**5 + 1):
  if i in s:
    count += 1
    l[i] = count
  else:
    l[i] = count
    
count = 0   
L = [0]*(10**5 + 1)

for i in range(1,50002):
  if l[i] - l[i-1] == 1 and  l[2*i - 1] - l[2*i - 2] == 1:
    count += 1
    L[i] = count
  else:
    L[i] = count
    
q = int(input())
for i in range(q):
  l,r = map(int,input().split())
  if L[l] - L[l-1] == 1:
    print(L[r] - L[l] + 1)
  else:
    print(L[r] - L[l])
    

Fixed code:
from math import floor,sqrt

def eratosthenes(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, floor(sqrt(n))+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table
  
s = set(eratosthenes(10**5))
l = [0]*(10**5 + 1)
count = 0

for i in s:
  l[i] = 1

count = 0   
L = [0]*(10**5 + 1)

for i in range(1,10**5 + 1):
  if i != 2 and l[i] == 1 and l[(i+1)//2] == 1:
    count += 1
    L[i] = count
  else:
    L[i] = count
    

q = int(input())
for i in range(q):
  l,r = map(int,input().split())
  if L[l] - L[l-1] == 1:
    print(L[r] - L[l] + 1)
  else:
    print(L[r] - L[l])
Buggy code:
INF = 10**5+1
ac = [0 for i in range(INF)]
memo = [True for i in range(INF)]
for i in range(2,INF):
    if memo[i]:
        for j in range(2*i,INF,i):
            memo[j] = False

for x in range(1,INF,2):
    ac[x] = 1 if memo[x] and memo[(x+1)//2] else 0
for x in range(1,INF):
    ac[x] += ac[x-1]
Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    print(ac[r]-ac[l-1])


Fixed code:
INF = 10**5+1
ac = [0 for i in range(INF)]
memo = [True for i in range(INF)]
for i in range(2,INF):
    if memo[i]:
        for j in range(2*i,INF,i):
            memo[j] = False

for x in range(3,INF,2):
    ac[x] = 1 if memo[x] and memo[(x+1)//2] else 0
for x in range(1,INF):
    ac[x] += ac[x-1]
Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    print(ac[r]-ac[l-1])
Buggy code:
MAX=100000
isprime=[1]*(MAX+1)
isprime[0]=0
isprime[1]=0

for i in range(2,int(pow(MAX,0.5)+1)):
    if isprime[i]==1:
        for j in range(i*2,MAX+1,i):
            isprime[j]=0

islike2017=[0]*(MAX)
for i in range(MAX):
    if isprime[i]==1 and isprime[int((i+1)/2)]==1:
        islike2017[i]=1

cumsum=[0]*(MAX+1)
for i in range(1,MAX+1):
    cumsum[i]=cumsum[i-1]+islike2017[i-1]

Q=int(input())
l=0
r=0
for i in range(Q):
    l, r = map(int, input().split())
    print(cumsum[r]-cumsum[l])

Fixed code:
MAX=100000
isprime=[1]*(MAX+1)
isprime[0]=0
isprime[1]=0

for i in range(2,int(pow(MAX,0.5)+1)):
    if isprime[i]==1:
        for j in range(i*2,MAX+1,i):
            isprime[j]=0

islike2017=[0]*(MAX)
for i in range(MAX):
    if isprime[i]==1 and isprime[int((i+1)/2)]==1:
        islike2017[i]=1

cumsum=[0]*(MAX+1)
for i in range(1,MAX+1):
    cumsum[i]=cumsum[i-1]+islike2017[i-1]

Q=int(input())
l=0
r=0
for i in range(Q):
    l, r = map(int, input().split())
    r=r+1
    print(cumsum[r]-cumsum[l])
Buggy code:
q = int(input())
lr = []
for i in range(q):
    lr.append(list(map(int, input().split())))


def binarySearch(alist, item):
    first = 0
    last = len(alist) - 1
    found = False
    while first <= last and not found:
        midpoint = (first + last) // 2
        if alist[midpoint] == item:
            found = True
        else:
            if item < alist[midpoint]:
                last = midpoint - 1
            else:
                first = midpoint + 1
    return found


def is_prime(num):
    i = 2
    while i ** 2 <= num:
        if num % i == 0:
            return False
        i += 1
    return True


primes = []
for i in range(3, 10 ** 5 + 1):
    if is_prime(i):
        primes.append(i)

like_2017 = []
for i in range(len(primes)):
    if binarySearch(primes, primes[i] * 2 - 1):
        like_2017.append(2 * primes[i] - 1)

count = [0 for _ in range(10 ** 5)]
for like in like_2017:
    count[like] += 1
count[1] = 1
for i in range(len(count) - 1):
    count[i + 1] += count[i]
for i in range(q):
    print(count[lr[i][1]-1] - count[lr[i][0]-1])


Fixed code:
q = int(input())
lr = []
for i in range(q):
    lr.append(list(map(int, input().split())))


def binarySearch(alist, item):
    first = 0
    last = len(alist) - 1
    found = False
    while first <= last and not found:
        midpoint = (first + last) // 2
        if alist[midpoint] == item:
            found = True
        else:
            if item < alist[midpoint]:
                last = midpoint - 1
            else:
                first = midpoint + 1
    return found


def is_prime(num):
    i = 2
    while i ** 2 <= num:
        if num % i == 0:
            return False
        i += 1
    return True


primes = []
for i in range(2, 10 ** 5 + 1):
    if is_prime(i):
        primes.append(i)

like_2017 = []
for i in range(len(primes)):
    if binarySearch(primes, primes[i] * 2 - 1):
        like_2017.append(2 * primes[i] - 1)

count = [0 for _ in range(10 ** 5)]
for like in like_2017:
    count[like] += 1
for i in range(len(count) - 1):
    count[i + 1] += count[i]
for i in range(q):
    print(count[lr[i][1]] - count[lr[i][0]-1])
Buggy code:
import itertools
import copy
q=int(input())
qr=[list(map(int,input().split())) for i in range(q)]
n=[1]*(10**5+1)
n[0]=0
k=2
while k<(10**5+1)**0.5+1:
  for i in range(2*k,10**5+1,k):
    n[i]=0
  if k==2:
    k+=1
  else:
    k+=2
k=copy.deepcopy(n)
for i in range(1,len(n)):
  if i%2==1 and k[i]==1 and k[(i+1)//2]==0:
    n[i]=0
    
#print(n)
ans=list(itertools.accumulate(n))
for i in range(q):
  print(ans[qr[i][1]]-ans[qr[i][0]-1])

Fixed code:
import itertools
import copy
q=int(input())
qr=[list(map(int,input().split())) for i in range(q)]
sosu=[1]*(10**5+1)
sosu[0]=0
sosu[1]=0
k=2
while k<(10**5+1)**0.5+1:
  for i in range(2*k,10**5+1,k):
    sosu[i]=0
  if k==2:
    k+=1
  else:
    k+=2
    
n=[0]*(10**5+1)
for i in range(1,len(sosu)):
  if i%2==1 and sosu[i]==1 and sosu[(i+1)//2]==1:
    n[i]=1
ans=list(itertools.accumulate(n))
for i in range(q):
  print(ans[qr[i][1]]-ans[qr[i][0]-1])
Buggy code:
import numpy as np


def solve(string):
    num_max = 100000
    primes = np.asarray([True for _ in range(num_max + 1)])
    for i in range(num_max + 1):
        if i == 0 or i == 1:
            primes[i] = False
        elif primes[i]:
            primes[i * 2::i] = False
    primes = set(np.arange(num_max + 1)[primes])
    like2017 = [1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(num_max + 1)]
    cumsum = np.cumsum(like2017)

    q, *lr = map(int, string.split())
    return [str(cumsum[r] - cumsum[l - 1]) for l, r in zip(lr[::2], lr[1::2])]


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Fixed code:
import numpy as np


def solve(string):
    num_max = 100000
    primes = np.asarray([True for _ in range(num_max + 1)])
    for i in range(num_max + 1):
        if i == 0 or i == 1:
            primes[i] = False
        elif primes[i]:
            primes[i * 2::i] = False
    primes = set(np.arange(num_max + 1)[primes])
    like2017 = [1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(num_max + 1)]
    cumsum = np.cumsum(like2017)

    q, *lr = map(int, string.split())
    return "\n".join([str(cumsum[r] - cumsum[l - 1]) for l, r in zip(lr[::2], lr[1::2])])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))
Buggy code:
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)


for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l) - 1
	b = bisect.bisect_left(p2017, r) - 1
	if p2017[b] == r:
		b += 1
	print(b - a)

Fixed code:
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)


for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_right(p2017, r)
	print(b - a)
Buggy code:
import math
from itertools import accumulate

def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

er_list = eratosthenes(100000)
count = []

j = 0
for i in range(er_list[-1]):
    if i == er_list[j]:
        j += 1
        if (i+1)//2 in er_list:
            count.append(1) 
        else:
            count.append(0)
            
count = list(accumulate(count))
            
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])

Fixed code:
import math
from itertools import accumulate

def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

max_lr = 100000
er_list = eratosthenes(max_lr)
count = [0] * max_lr


for i in range(len(er_list)):
    if (er_list[i]+1)//2 in er_list:
        count[er_list[i]] = 1
            
count = list(accumulate(count))
            
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])
Buggy code:
Q = int(input())
lr = []
maxr = 0
for i in range(Q):
    l,r = map(int,input().split())
    maxr = max(maxr,r)
    lr.append([l,r])
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    is_prime[2] = False
    return [2]+[i for i in range(3,n + 1) if is_prime[i] and is_prime[(i+1)//2]]
prime = primes(maxr)
import bisect
for l,r in lr:
    print(bisect.bisect_right(prime,r)-bisect.bisect_right(prime,l-1))
    
    

Fixed code:
Q = int(input())
lr = []
maxr = 0
for i in range(Q):
    l,r = map(int,input().split())
    maxr = max(maxr,r)
    lr.append([l,r])
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(3,n + 1) if is_prime[i] and is_prime[(i+1)//2]]
prime = primes(maxr)
import bisect
for l,r in lr:
    print(bisect.bisect_right(prime,r)-bisect.bisect_right(prime,l-1))