To check if a number is prime
let isPrime = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { isPrime [ i ] = true ; } isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i < MAX ; i ++ ) {