Time limit exceeded in question https://online.codingblocks.com/app/player/37589/content/18299/4747

Even after aplying prime seive one test case is still showing TLE.

t=int(input())
while t>0:
l=[int(x) for x in input().split()]
a=l[0]
n=l[1]
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):

    if (prime[p] == True): 
          
        
        for i in range(p * p, n+1, p): 
            prime[i] = False
    p += 1
  

for p in range(a, n+1): 
    if prime[p]: 
        if p >1:

            print (p,end=" ")
print()
t-=1

Hey manan,
You are creating prime number again again for every testcase, what you can do is just create a single prime number array by looking at the max and min constraints given in question. This way you might save some time.
Otherwise it would be bit difficult to pass TLE with python… or you can try with C++ since it is quite fast.
And this question is not anyhow related to data science, you can skip this as well. That won’t make any affect on your learning

Thanks :slight_smile:

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.