Initially all numbers are considered Primes .
for ( let i = 0 ; i < N + 10 ; i ++ ) sieve [ i ] = true ; for ( let i = 2 ; i <= N ; i ++ ) { if ( sieve [ i ] ) { for ( let j = i * i ; j <= N ; j += i ) { sieve [ j ] = false ; } } }