Time limit exceed for the 2nd test case

I am trying on this problem for long now, and have implemented the fastest algorithm possible for prime generations. But, still, it’s showing ‘timelimit’ for the 2nd case. Please help me with it.

Hello @RahulNM19,

Can you please share your code with us.

Thanks :slight_smile:

i am also getting timelimit for the 2nd case…
here is my code…

import math
t=int(input())
for k in range(t):
m,n=input().split()
m=int(m)
n=int(n)
for i in range(m,n+1):
c=0
for j in range(2,int(math.sqrt(i))+1):
if i%j==0:
c+=1
break
if c==0 and i!=1:
print(i,end=’ ')
print()

Hello @ayushi1719,

Those challenges are designed for the ds algo batches, hence are specifically targetted towards C++. Hence, even if you are applying the best algorithm, the reason why python is used, it can show you time limit exceeded as it is slower. Therefore, kindly submit the solution in C++ or Java. That will give you the score.

We are working towards easing this problem.
Happy Learning :slight_smile:
Thanks

Sir, I also tried to code the solution in C++ but, still got the time exceed error.
:frowning:

Hello @RahulNM19 ,

Hint:
You have to use the sieve method for this challenge. :wink:

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.