Time limit in my program of prime generators

my program always returns time limit for both the test cases. Here’s the code-
def checkprime(m,n):
alist = [var for var in range(m,n+1)]
blist=[]
for i in range(m, n+1):
for j in range(2,i):
if i % j == 0:
blist.append(i)
clist=list(set(alist) - set(blist))
if 1 in clist: clist.remove(1)
for i in clist:
print(i,end=" “)
print(”")

x=int(input(“enter-”))
m=0
n=0
b=[]
for i in range(0,x):
a=input()
b.append(a)

for i in b:
j=i.split()
m=int(j[0])
n=int(j[1])
checkprime(m,n)

The code which you have written is taking longer than alloted time to get executed , the reason for this is the use of nested for loops inside the checkprime function .
In order to reduce the time taken I would suggest that you look into “sieves of primes” algorithm .
You can find the video on same here- https://online.codingblocks.com/courses/data-structures-and-algorithms-online-course. It is present as a free trial .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

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