Javascript implementation of above approach
let MAX = 105 , q = 0 ; let prime = new Array ( MAX ) ; function sieve ( ) { for ( let i = 2 ; i * i < MAX ; i ++ ) { if ( prime [ i ] == 0 ) { for ( let j = i * i ; j < MAX ; j += i ) prime [ j ] = 1 ; } } }