hello sir,
I gone through the prime sieve code, and i find one more optimisation that we could do for the outer loop like we have only need outer loop to run until ii<=n
For e.g-> for(int i=3;ii<=n;i+=2) instead of for(int i=3;i<=n;i+=2);
please confirm this sir.
Prime Sieve code
Hi krishh25
Yes, you can use for(int i=3;i*i<=n;i++). It is optimised version.
And make sure you do it for i=2 before it.
More optimised version can be seen here : https://www.topcoder.com/community/competitive-programming/tutorials/mathematics-for-topcoders/
Hope it helps
Please mark resolved if satisfied
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.