Where am i going worng in prime sieve implimentation
@itismohiton hey,dont take the seive array size to b take the max contraint size of no a and b which is given in question ,seive[b] is not correct instead of b take the upper constraint of an b.
why i can’t take array size as b? Also i am getting tle during submission on hackerblocks, after your suggested changes.
and can you please tell me what is wrong in this code?
@itismohiton hey here is your corrected code:
int prime[1000000];
for(int i=2;i<1000000;i++)
prime[i]=1;
prime[1]=0;
prime[0]=0;
for(int i=2;i * i<1000000;i++)
{
if(prime[i]==1)
{
for(int j=i * i;j<1000000;j+=i)
{
prime[j]=0;
}
}
}
We will go till biggest constraint as we have to see all the prime factors of no till max constraint,please dry run above code you will get it.
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.