Tle error help neede

how to do this

def prime(m,n):
for i in range(m,n + 1):
f = 0
for j in range(2,int(i**0.5) + 1):
if(i % j == 0):
f = 1
break
if(f == 0):
if(i != 0 and i != 1):
print(i)
t = int(input())
for x in range(t):
count = 0
l = list(map(int,input().split()))
prime(l[0],l[1])

my code above

Please share your code using

If you still have some questions or not find the answers satisfactory, you may reopen the doubt.

please check now it’s producing tle

The idea is to use Sieve of Eratosthenes.
First find primes in the range from 0 to start (m) and store it in a vector. Similarly, find primes in the range from 0 to end (n) and store in another vector. Then ans is difference between the two.
We take a boolean list and mark ith index false if it is not a prime.
Something like this -

import math
def sieve(n):
    primes = [True]*n
    primes[0] = False
    primes[1] = False
    for i in range(2,int(math.sqrt(n))+1):
            j = i*i
            while j < n:
                    primes[j] = False
                    j = j+i
    return [x for x in range(n) if primes[x] == True]