Here prime numbers are checked till the maximum number of bits possible because that the maximum bit sum possible is the number of bits itself .
let primeArr = SieveOfEratosthenes ( Math . ceil ( Math . log ( y , 2 ) ) ) ; for ( let i = x ; i < y + 1 ; i ++ ) { let temp = setBits ( i ) ; if ( primeArr . includes ( temp ) ) count += 1 ; } document . write ( count ) ;