Count of elements in an Array whose set bits are in a multiple of K | C # 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
using System ; class GFG { static int find_count ( int [ ] arr , int k ) { int ans = 0 ; foreach ( int i in arr ) { int x = countSetBits ( i ) ; if ( x % k == 0 ) ans += 1 ; } return ans ; } static int countSetBits ( long x ) { int setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } public static void Main ( String [ ] args ) { int [ ] arr = { 12 , 345 , 2 , 68 , 7896 } ; int K = 2 ; Console . Write ( find_count ( arr , K ) ) ; } }