why is it showing tle
Prime generator
Hey @naazsayma123, TLE stands for Time Limit Exceeded. Now your code logic is correct and is producing exactly the correct results. But the time complexity of your code is O(n^2)
. Try to reduce the complexity on your own first. Hint : I don’t think you really need to check from 2
to p
for every number in prime()
function. If the number is even, then directly skip that number as it will never be prime. Check only for odd numbers. Likewise you can try reducing the complexity.
You would get to learn the logic once you try on your own !
Hope this helps !
Happy coding
What changes did u make? Please let me know.
i did this
Okay so there is a concept called “Sieve of Eratosthenes”. That helps reduces the time complexity by a large extent. I am attaching a resource for your kind reference :
Please go through this and use the concept in this problem.
I hope this helps !
Happy Learning !
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.