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