qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def prime(n):
    is_prime=[True]*(n+1)
    is_prime[0],is_prime[1]=False,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(n+1) if is_prime[i]]

prime_number=prime(10**5)
number=[i for i in prime_number if (i+1)//2 in prime_number]
ans=[0]*(10**5+1)
count=0
for i in range(1,10**5):
    ans[i]=ans[i-1]
    if i==number[count]:
        ans[i] +=1
        count +=1

for i in range(int(input())):
    a,b=map(int,input().split())
    print(ans[b]-ans[a-1])

Fixed code:
def prime(n):
    is_prime=[True]*(n+1)
    is_prime[0],is_prime[1]=False,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(n+1) if is_prime[i]]

prime_number=prime(10**5)
number=[i for i in prime_number if (i+1)//2 in prime_number]+[0]
ans=[0]*(10**5+1)
count=0
for i in range(1,10**5):
    ans[i]=ans[i-1]
    if i==number[count]:
        ans[i] +=1
        count +=1

for i in range(int(input())):
    a,b=map(int,input().split())
    print(ans[b]-ans[a-1])
Buggy code:
import bisect
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=[i for i in primes if (i+1)//2 in primes]
q=int(input())
for i in range(q):
    a,b=map(int, input().split())
    print(bisect.bisect_right(primes, 7)-bisect.bisect_left(primes, 3))

Fixed code:
import bisect
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=[i for i in primes if (i+1)//2 in primes]
q=int(input())
for i in range(q):
    a,b=map(int, input().split())
    print(bisect.bisect_right(primes, b)-bisect.bisect_left(primes, a))
Buggy code:
from math import ceil, sqrt

n = 10**5+200
hurui = [i for i in range(n+1)]
for i in range(2,ceil(sqrt(n))+1):
    for j in range(2,ceil(sqrt(i))+1):
        if i==2:
            continue
        if i%j == 0:
            break
    else:
        for k in range(i+i,n,i):
            if hurui[k] != k:
                continue
            hurui[k] = 0
    continue

hurui = [bool(i) for i in hurui]
poi = [False]*(n+1)
poi[1] = False
for i in range(n+1):
    # print(i)
    poi[i] = (i % 2 == 1 and hurui[i] and hurui[(i+1)//2])
#print(poi)
sa = [0]
for i in range(n+1):
    sa.append(sa[i]+poi[i])
#print(sa[:10])

#print(poi[2017])
#print(poi[:10])

q = int(input())
lr = [tuple(map(int,input().split())) for i in range(q)]
for li,ri in lr:
    print(sa[ri+1]-sa[li])


Fixed code:
from math import ceil, sqrt


def eratosthenes(n):
    hurui = [i for i in range(n + 1)]
    for i in range(2, ceil(sqrt(n)) + 1):
        for j in range(2, ceil(sqrt(i)) + 1):
            if i == 2:
                continue
            if i % j == 0:
                break
        else:
            for k in range(i + i, n, i):
                if hurui[k] != k:
                    continue
                hurui[k] = 0
        continue
    return hurui


n = 10**5 + 200
hurui = eratosthenes(n)
hurui = [bool(i) for i in hurui]
poi = [False] * (n + 1)
for i in range(n + 1):
    poi[i] = (i % 2 == 1 and hurui[i] and hurui[(i + 1) // 2])
poi[1] = False
sa = [0]
for i in range(n + 1):
    sa.append(sa[i] + poi[i])
q = int(input())
lr = [tuple(map(int, input().split())) for i in range(q)]
for li, ri in lr:
    print(sa[ri + 1] - sa[li])
Buggy code:
from math import ceil, sqrt

n = 10**5+200
hurui = [i for i in range(n+1)]
for i in range(2,ceil(sqrt(n))+1):
    for j in range(2,ceil(sqrt(i))+1):
        if i==2:
            continue
        if i%j == 0:
            break
    else:
        for k in range(i+i,n,i):
            if hurui[k] != k:
                continue
            hurui[k] = 0
    continue

hurui = [bool(i) for i in hurui]
poi = [False]*(n+1)
for i in range(n+1):
    # print(i)
    poi[i] = (i % 2 == 1 and hurui[i] and hurui[(i+1)//2])
#print(poi)
sa = [0]
for i in range(n+1):
    sa.append(sa[i]+poi[i])
#print(sa[:10])

#print(poi[2017])
a = 0
for i in range(1,56):
    a += poi[i]
# print(a)

q = int(input())
lr = [tuple(map(int,input().split())) for i in range(q)]
for li,ri in lr:
    print(sa[ri+1]-sa[li])


Fixed code:
from math import ceil, sqrt

n = 10**5+200
hurui = [i for i in range(n+1)]
for i in range(2,ceil(sqrt(n))+1):
    for j in range(2,ceil(sqrt(i))+1):
        if i==2:
            continue
        if i%j == 0:
            break
    else:
        for k in range(i+i,n,i):
            if hurui[k] != k:
                continue
            hurui[k] = 0
    continue

hurui = [bool(i) for i in hurui]
poi = [False]*(n+1)
for i in range(n+1):
    # print(i)
    poi[i] = (i % 2 == 1 and hurui[i] and hurui[(i+1)//2])
poi[1] = False
#print(poi)
sa = [0]
for i in range(n+1):
    sa.append(sa[i]+poi[i])
#print(sa[:10])

#print(poi[2017])

q = int(input())
lr = [tuple(map(int,input().split())) for i in range(q)]
for li,ri in lr:
    print(sa[ri+1]-sa[li])
Buggy code:
Q = int(input())

M = 10**5+5
primes = [True] * M
primes[0] = False
primes[1] = False


for i in range(2, M):
    if primes[i]:
        for j in range(2, M//i+1):
            primes[i*j] = False

print(primes)
cnt = [0] * M

for i in range(3, M):
    cnt[i] = cnt[i-1]
    if primes[i] and primes[(i+1)//2]:
        cnt[i] += 1
print(cnt)
queues = []
for q in range(Q):
    l, r = map(int, input().split())
    queues.append((l, r))

for l, r in queues:
    print(cnt[r] - cnt[l-1])


Fixed code:
Q = int(input())

M = 10**5+5
primes = [True] * M
primes[0] = False
primes[1] = False


for i in range(2, M):
    if primes[i]:
        for j in range(2, (M-1)//i+1):
            primes[i*j] = False

# print(primes)                                                                    
cnt = [0] * M

for i in range(3, M):
    cnt[i] = cnt[i-1]
    if primes[i] and primes[(i+1)//2]:
        cnt[i] += 1
# print(cnt)                                                                       
queues = []
for q in range(Q):
    l, r = map(int, input().split())
    queues.append((l, r))

for l, r in queues:
    print(cnt[r] - cnt[l-1])
Buggy code:
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime
    

Q = int(input())
N = 10**5

prime = eratosthenes(N)
prime_num = [0 for i in range(N+1)]
for p in prime:
    prime_num[p] = 1
    
count = 0
ans = [0 for i in range(N+1)]
for i in range(1, N+1, 2):
    if prime_num[i] == 1 and prime_num[(i+1)//2] == 1:
        count += 1
    ans[i] = count
    
for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r+2] - ans[l-2])

Fixed code:
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime
    

Q = int(input())
N = 10**5

prime = eratosthenes(N)
prime_num = [0 for i in range(N+1)]
for p in prime:
    prime_num[p] = 1
    
count = 0
ans = [0 for i in range(N+1)]
for i in range(1, N+1, 2):
    if prime_num[i] == 1 and prime_num[(i+1)//2] == 1:
        count += 1
    ans[i] = count
    
for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r] - ans[l-2])
Buggy code:
Q = int(input())
LR = [list(map(int,input().split())) for _ in range(Q)]

prime = [1]*(10**5 + 10)
for i in range(2,10**5+10):
    if prime[i]:
        for j in range(2*i,10**5 + 10,i):
            prime[j] = 0

Ans = [0]*(10**5 + 10)

for a in range(1,10**5 + 9):
    if prime[a] and prime[int((a+1)/2)]:
        Ans[a] = 1
    Ans[a] += Ans[a-1]

for l,r in LR:
    print(Ans[r]-Ans[l-1])



Fixed code:
Q = int(input())
LR = [list(map(int,input().split())) for _ in range(Q)]

prime = [1]*(10**5 + 10)
prime[1] = 0
for i in range(2,10**5+10):
    if prime[i]:
        for j in range(2*i,10**5 + 10,i):
            prime[j] = 0

Ans = [0]*(10**5 + 10)

for a in range(2,10**5 + 9):
    if prime[a] and prime[int((a+1)/2)]:
        Ans[a] = 1
    Ans[a] += Ans[a-1]

for l,r in LR:
    print(Ans[r]-Ans[l-1])
Buggy code:
from math import sqrt
import bisect


def is_prime(num):
    if num < 2:
        return True
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    sqrtNum = sqrt(num)
    for i in range(3, int(sqrtNum) + 1, 2):
        if num % i == 0:
            return False

    return True


def solve(query):
    ans = []
    al = []
    for i in range(3, 10**5+1, 2):
        if is_prime(i) and is_prime((i+1)//2):
            al.append(i)

    for q in query:
        if is_prime(q[0]) and is_prime((q[0]+1)//2):
            l_ind = bisect.bisect_right(al, q[0]) - 1
        else:
            l_ind = bisect.bisect_right(al, q[0])
        if is_prime(q[1]) and is_prime((q[1]+1)//2):
            r_ind = bisect.bisect_left(al, q[1])
        else:
            r_ind = bisect.bisect_left(al, q[1]) - 1
        ans.append(r_ind-l_ind+1)

    return ans


if __name__ == "__main__":
    Q = int(input())
    query = [list(map(int, input().split())) for _ in range(Q)]

    ans = solve(query)

    for a in ans:
        print(a)


Fixed code:
from math import sqrt
import bisect


def is_prime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    sqrtNum = sqrt(num)
    for i in range(3, int(sqrtNum) + 1, 2):
        if num % i == 0:
            return False

    return True


def solve(query):
    ans = []
    al = []
    for i in range(3, 10**5+1, 2):
        if is_prime(i) and is_prime((i+1)//2):
            al.append(i)

    for q in query:
        if is_prime(q[0]) and is_prime((q[0]+1)//2):
            l_ind = bisect.bisect_right(al, q[0]) - 1
        else:
            l_ind = bisect.bisect_right(al, q[0])
        if is_prime(q[1]) and is_prime((q[1]+1)//2):
            r_ind = bisect.bisect_left(al, q[1])
        else:
            r_ind = bisect.bisect_left(al, q[1]) - 1
        ans.append(r_ind-l_ind+1)

    return ans


if __name__ == "__main__":
    Q = int(input())
    query = [list(map(int, input().split())) for _ in range(Q)]

    ans = solve(query)

    for a in ans:
        print(a)
Buggy code:
import math
import numpy as np
def get_prime(n):
    if n<= 1:
        return[]
    prime = [2]
    limit = int(math.sqrt(n))
    
    data = [i + 1 for i in range(2,n,2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
n = int(input())
l = []
r = []
for i in range(n):
    l_, r_ =map(int,input().split())
    l.append(l_)
    r.append(r_)
a = get_prime(10**5+1)
b = np.array([0]*(10**5+2))
c =0
d = 0
add = 0
for i in range(1,len(a)):
    if is_prime((a[i]+1)/2):
        d = a[i] +1
        b[c:d] = add 
        c = d
        add +=1
for i in range(n):
    if l[i] == r[i]:
        if is_prime((l[i]+1)/2):
            print(1)
        else:
            print(0)
    else:
        e = b[l[i]+1]
        f = b[r[i]+1]
        print(f - e)

Fixed code:
import math
import numpy as np
def get_prime(n):
    if n<= 1:
        return[]
    prime = [2]
    limit = int(math.sqrt(n))
    
    data = [i + 1 for i in range(2,n,2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
n = int(input())
l = []
r = []
for i in range(n):
    l_, r_ =map(int,input().split())
    l.append(l_)
    r.append(r_)
a = get_prime(10**5+1)
b = np.array([0]*(10**5+2))
c =0
d = 0
add = 0
for i in range(1,len(a)):
    if is_prime((a[i]+1)/2):
        d = a[i] 
        b[c:d] = add 
        c = d
        add +=1
b[c:] = add 
b[0::2] = 0
for i in range(n):
    e = b[max(0, l[i] - 2)]
    f = b[r[i]]
    print(f - e)
Buggy code:
n=100000
p=[0]*2+[1]*(n-1)
for i in range(2,n+1):
  if p[i]:
    for j in range(i*2,n+1,i):
      p[j]=0
for i in range(1,n+1)[::-1]:
  if p[i]:
    if p[(i+1)//2]:
      continue
    p[i]=0
p[2]=0
c=[0]*n
for i in range(1,n+1):
  c[i]=c[i-1]+p[i]
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(c[r]-c[l-1])

Fixed code:
n=100000
p=[0]*2+[1]*(n-1)
for i in range(2,n+1):
  if p[i]:
    for j in range(i*2,n+1,i):
      p[j]=0
for i in range(1,n+1)[::-1]:
  if p[i]:
    if p[(i+1)//2]:
      continue
    p[i]=0
p[2]=0
c=[0]*(n+1)
for i in range(1,n+1):
  c[i]=c[i-1]+p[i]
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(c[r]-c[l-1])
Buggy code:
import bisect

q = int(input())

def PRIME(N):
    LIM = int(N**0.5)+2
    for i in range(2, LIM):
        if N%i == 0:
            return False
    return True

prime, ans = {2:True}, []
for i in range(3, 100001):
    if i%2 == 0:
        prime[i] = False
        continue
    a = PRIME(i)
    prime[i] = a
    if a:
        if prime[(i+1)//2]:
            ans.append(i)

for _ in range(q):
    l, r = map(int, input().split())
    L = bisect.bisect_left(ans, l)
    R = bisect.bisect_left(ans, r)
    print(R-L)

Fixed code:
import bisect

def PRIME(N):
    LIM = int(N**0.5)+2
    for i in range(2, LIM):
        if N%i == 0:
            return False
    return True

q = int(input())
prime, ans = {2:True}, []
for i in range(3, 100001):
    if i%2 == 0:
        prime[i] = False
        continue
    a = PRIME(i)
    prime[i] = a
    if a:
        if prime[(i+1)//2]:
            ans.append(i)

for _ in range(q):
    l, r = map(int, input().split())
    L = bisect.bisect_left(ans, l)
    R = bisect.bisect_right(ans, r)
    print(R-L)
Buggy code:
q=int(input())
n =10**3
prime = {i for i in range(2,n)}
for i in range(2,n):
    if i in prime:
        for j in range(i*2,n,i):
            if j in prime:
                prime.remove(j)
lists=[]
for i in prime:
    lists.append(i)  
lists=sorted(lists) 

checklist=[0]*(10**5+1)
checklist[0]=0
checklist[1]=0
for i in range(2,10**5+1):
    if i%2==0:
        checklist[i]=checklist[i-1]
    elif i%2!=0:
        if (all(i%j!=0 for j in lists) or i in lists) and (all(((i+1)//2)%j!=0 for j in lists) or (i+1)//2 in lists) :
            count+=1
            checklist[i]=checklist[i-1]+1
        else:
            checklist[i]=checklist[i-1]

listss=[0]*q
for i in range(q):
    a,b=map(int,input().split())
    c=checklist[b]-checklist[a-1]
    listss[i]=c
for i in listss:
    print(i)


Fixed code:
q=int(input())
n =10**3
prime = {i for i in range(2,n)}
for i in range(2,n):
    if i in prime:
        for j in range(i*2,n,i):
            if j in prime:
                prime.remove(j)
lists=[]
for i in prime:
    lists.append(i)  
lists=sorted(lists) 

checklist=[0]*(10**5+1)
checklist[0]=0
checklist[1]=0
count=0
for i in range(2,10**5+1):
    if i%2==0:
        checklist[i]=checklist[i-1]
    elif i%2!=0:
        if (all(i%j!=0 for j in lists) or i in lists) and (all(((i+1)//2)%j!=0 for j in lists) or (i+1)//2 in lists) :
            count+=1
            checklist[i]=checklist[i-1]+1
        else:
            checklist[i]=checklist[i-1]

listss=[0]*q
for i in range(q):
    a,b=map(int,input().split())
    c=checklist[b]-checklist[a-1]
    listss[i]=c
for i in listss:
    print(i)
Buggy code:
N = int(input())

maxp = 100100

allPrimes = [1]
like2017 = []
primes_list = [0 for _ in range(maxp+1)]
import bisect

def isPrimeNum(num):
    if num in allPrimes:
        return True
    else:
        return False

def initPrimes(ma):
    furui = {i:0 for i in range(2,ma+1)}

    primes_list[1] = 1

    for i in range(2,ma):
        if furui[i] == 0:
            
            if i > 2 and primes_list[(i+1)//2] == 1:
                like2017.append(i)

            primes_list[i] = 1

            for h in range(1,ma):
                index = i * h
                if index>ma:
                     break
                furui[index] = 1




initPrimes(maxp)

print(like2017)

count = 0
for _ in range(N):
    l,r = [int(x) for x in input().split()]

    f = bisect.bisect_left(like2017,l)
    t = bisect.bisect_right(like2017,r)

    print(t-f)


Fixed code:
N = int(input())

maxp = 100100

allPrimes = [1]
like2017 = []
primes_list = [0 for _ in range(maxp+1)]
import bisect

def isPrimeNum(num):
    if num in allPrimes:
        return True
    else:
        return False

def initPrimes(ma):
    furui = {i:0 for i in range(2,ma+1)}

    primes_list[1] = 1

    for i in range(2,ma):
        if furui[i] == 0:
            
            if i > 2 and primes_list[(i+1)//2] == 1:
                like2017.append(i)

            primes_list[i] = 1

            for h in range(1,ma):
                index = i * h
                if index>ma:
                     break
                furui[index] = 1




initPrimes(maxp)

count = 0
for _ in range(N):
    l,r = [int(x) for x in input().split()]

    f = bisect.bisect_left(like2017,l)
    t = bisect.bisect_right(like2017,r)

    print(t-f)
Buggy code:
from bisect import bisect_left, bisect_right
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(3, 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(n + 1) if is_prime[i]]

prime = primes(10**5)
p_set = set(prime)
like = [3]
for i in prime:
    if (i+1)//2 in p_set:
        like.append(i)

Q = int(input())
for _ in range(Q):
    l, r = map(int,input().split())
    print(bisect_right(like, r) - bisect_left(like, l))

Fixed code:
from bisect import bisect_left, bisect_right
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]]

prime = primes(10**5)
p_set = set(prime)
like = [3]
for i in prime:
    if (i+1)//2 in p_set:
        like.append(i)

Q = int(input())
for _ in range(Q):
    l, r = map(int,input().split())
    print(bisect_right(like, r) - bisect_left(like, l))
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

s = set()
for i in range(2, 10**5+5):
    if i in s:
        continue
    cnt = 2
    while i*cnt<=10**5+5:
        s.add(i*cnt)
        cnt += 1

from itertools import accumulate

lis = [0]*(10**5+5)
for i in range(1, 10**5+5, 2):
    if not i in s and not (i+1)//2 in s:
        lis[i] = 1

lis = list(accumulate(lis))
Q = int(input())
for _ in range(Q):
    l, r = mapint()
    print(lis[r]-lis[l-1])

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

s = set()
for i in range(2, 10**5+5):
    if i in s:
        continue
    cnt = 2
    while i*cnt<=10**5+5:
        s.add(i*cnt)
        cnt += 1

from itertools import accumulate

lis = [0]*(10**5+5)
for i in range(3, 10**5+5, 2):
    if not i in s and not (i+1)//2 in s:
        lis[i] = 1

lis = list(accumulate(lis))
Q = int(input())
for _ in range(Q):
    l, r = mapint()
    print(lis[r]-lis[l-1])
Buggy code:
def main():
    import math
    def generate_primes(num):
        if num == 1: return []
        primes = list(range(2, num + 1))
        i, p = 0, 1
        while p <= math.sqrt(num):
            if primes[i] != 0:
                p = primes[i]
                primes = [prime if (prime % p != 0 or prime == p) else 0 for prime in primes]
            i += 1
        return set([p for p in primes if p != 0])

    primes = generate_primes(100000)
    ans = [0] * 50000
    for j in range(1, 50000):
        i = 2 * j + 1
        if i in primes and (i + 1) / 2 in primes:
            ans[j] = ans[j - 1] + 1
        else:
            ans[j] = ans[j - 1]
    q = int(input())
    for _ in range(q):
        l, r = list(map(lambda x: (int(x) - 1) // 2, input().split()))
        print(ans[r] - ans[l - 1])


if __name__ == '__main__':
    main()


Fixed code:
def main():
    import math
    def generate_primes(num):
        if num == 1: return []
        primes = list(range(2, num + 1))
        i, p = 0, 1
        while p <= math.sqrt(num):
            if primes[i] != 0:
                p = primes[i]
                primes = [prime if (prime % p != 0 or prime == p) else 0 for prime in primes]
            i += 1
        return set([p for p in primes if p != 0])

    primes = generate_primes(100000)
    ans = [0] * 50001
    for j in range(1, 50001):
        i = 2 * j - 1
        if i in primes and (i + 1) // 2 in primes:
            ans[j] = ans[j - 1] + 1
        else:
            ans[j] = ans[j - 1]
    q = int(input())
    for _ in range(q):
        l, r = list(map(lambda x: (int(x) + 1) // 2, input().split()))
        print(ans[r] - ans[l - 1])


if __name__ == '__main__':
    main()
Buggy code:
import math
from itertools import accumulate

Q = int(input())
LR = []

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    # print(int(math.sqrt(n)))
    for i in range(2,int(math.sqrt(n))+1):
        for j in range(i*2, n+1 ,i):
            is_prime[j] = False

    return is_prime

def like2017(is_prime,n):
    solve = [0] * (n+1)
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[int((i+1)/2)]:
            solve[i] = 1
        
    return solve

for _ in range(Q):
    t = [int(i) for i in input().split(' ')]
    LR.append(t)

L = 100
is_prime = primes(L)
solve = like2017(is_prime,L)
# print(solve)
ans = list(accumulate(solve))
# print(ans)

for l, r in LR:
    print(ans[r] - ans[l-1])

Fixed code:
import math
from itertools import accumulate

Q = int(input())
LR = []

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    # print(int(math.sqrt(n)))
    for i in range(2,int(math.sqrt(n))+1):
        for j in range(i*2, n+1 ,i):
            is_prime[j] = False

    return is_prime

def like2017(is_prime,n):
    solve = [0] * (n+1)
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[int((i+1)/2)]:
            solve[i] = 1
        
    return solve

for _ in range(Q):
    t = [int(i) for i in input().split(' ')]
    LR.append(t)

L = 10 ** 5
is_prime = primes(L)
solve = like2017(is_prime,L)
# print(solve)
ans = list(accumulate(solve))
# print(ans)

for l, r in LR:
    print(ans[r] - ans[l-1])
Buggy code:
max_lr = 10 ** 5

sieve = [True] * (max_lr + 1)
sieve[0] = False
sieve[1] = False
for i in range(2, max_lr + 1):
    if sieve[i]:
        continue
    for j in range(i * i, max_lr + 1, i):
        sieve[j] = False

cs = [0] * (max_lr + 1)
for i in range(3, max_lr + 1, 2):
    if sieve[i] and sieve[(i + 1) // 2]:
        cs[i] = 1
for i in range(1, max_lr + 1):
    cs[i] += cs[i - 1]

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


Fixed code:
max_lr = 10 ** 5

sieve = [True] * (max_lr + 1)
sieve[0] = False
sieve[1] = False
for i in range(2, max_lr + 1):
    if not sieve[i]:
        continue
    for j in range(i * i, max_lr + 1, i):
        sieve[j] = False

cs = [0] * (max_lr + 1)
for i in range(3, max_lr + 1, 2):
    if sieve[i] and sieve[(i + 1) // 2]:
        cs[i] = 1
for i in range(1, max_lr + 1):
    cs[i] += cs[i - 1]

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