Time limit exceeded

def gen(x,y):
for i in range(x,y+1):
if i==1:
continue
flag=0
for j in range (2,i):
if(i%j==0):
flag=1
break
if(flag==0):
print(i,end=" ")

n=int(input())
for i in range(n):
x=input().split(" “)
gen(int(x[0]),int(x[1]))
print(”")

hey @ajaysiddartha ,
its still some logic problem.
The current logic is correct but the looping is very large and hence takes time.
You need to reduce your usage of such loops.

Try memoization , that can be of bit help.
But as you know python is not that fast. So , if it gets a large input , then it will surely longer time.

Hope you understand that.
Thank You and Happy Learning :slightly_smiling_face:.