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 .
primeArr = SieveOfEratosthenes ( int ( m . ceil ( m . log ( y , 2 ) ) ) ) NEW_LINE for i in range ( x , y + 1 ) : NEW_LINE INDENT temp = setBits ( i ) NEW_LINE if temp in primeArr : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE