TDPRIMES - TLE Even with Optimized Prime Sieves

Problem: https://www.spoj.com/problems/TDPRIMES/
Code: https://ide.codingblocks.com/s/79508

My code is taking 3+ second, the time limit is about 1 second.
Any resource would be helpful.

Thanks!


AC 1.32s

1 Like

Are you considering 1 is not prime and 0 as prime in the pr array?

whats wrong with my new solution: https://ide.codingblocks.com/s/79701

use bool array
thats quite fast

No output when using bool array… https://ide.codingblocks.com/s/79730


it is giving output.
you dont have to initialise bool array to true , we can do otherwise too.
just save time . dont do extra things which are not required

1 Like

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.