You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Mark all the 0s with 1s, if the corresponding number is composite. e.g. for 2, mark all the numbers which are multiples of 2
for (int i = 2; i * i <= n; i++) // i*i<=n or i<=sqrt(n) is based on the fact that one of the factor of a non-prime number/composite number must be less than or equal to its square root.
{
if (prime[i] == 0) // Avoids extra iterations
{
for (int j = i * i; j <= n; j += i) // j=i*i, Because the numbers before their squares have already been marked.