Count of elements in an Array whose set bits are in a multiple of K | Java implementation of above approach ; 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
class GFG { static int find_count ( int [ ] arr , int k ) { int ans = 0 ; for ( int i : arr ) { int x = Integer . bitCount ( i ) ; if ( x % k == 0 ) ans += 1 ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 12 , 345 , 2 , 68 , 7896 } ; int K = 2 ; System . out . print ( find_count ( arr , K ) ) ; } }