I’m getting TLE in all the cases, how can I further optimize the code?
My code-: https://ide.codingblocks.com/s/288794
Question-: https://hack.codingblocks.com/app/practice/3/67/problem
PrateekLoves Candy
hello @amarshmalik0
store all prime numbers upto 10^6 in some array .
and then use that array to print nth prime in O(1) per query
I’ve created a sieve array and i’m outputting the nth prime number from that array in o(n), what modification can I do in my code?
My time complexity comes out to be the same as yours, could you please point out the mistake that i’ve done in my code?
no time compleity are not same.
in urs case u r calling sieve for each query due which timr complexity is O( q * time to make sieve )
where in my solution i m calling only once and then for each query i m uising that sieve data.
so time compleity is
O( q + time to make sieve)
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.