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 ( Convert . ToInt32 ( Math . Ceiling ( Math . Log ( y , 2.0 ) ) ) ) ; for ( int i = x ; i < y + 1 ; i ++ ) { int temp = setBits ( i ) ; if ( primeArr . Contains ( temp ) ) count += 1 ; } Console . WriteLine ( count ) ; } }