Count of elements in an Array whose set bits are in a multiple of K | Function to find the count of numbers ; Get the set - bits count of each element ; Check if the setbits count is divisible by K ; Increment the count of required numbers by 1 ;  ; Driver code
function find_count ( arr , k ) { var ans = 0 ; for ( var i = 0 ; i <= arr . length ; i ++ ) { var x = countSetBits ( i ) ; if ( x % k == 0 ) ans += 1 ; } return ans ; } function countSetBits ( x ) { var setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } var arr = [ 12 , 345 , 2 , 68 , 7896 ] ; var K = 2 ; document . write ( find_count ( arr , K ) ) ;