#K66057. Count Elements with K Ones in Binary Representation
Count Elements with K Ones in Binary Representation
Count Elements with K Ones in Binary Representation
Given an array of integers and an integer \( k \), your task is to count the number of elements in the array whose binary representation contains exactly \( k \) ones. For example, the binary representation of 3 is \( 11 \) which has 2 ones.
The solution should read input from stdin and write the answer to stdout.
inputFormat
The first line contains two integers \( n \) and \( k \) separated by a space, where \( n \) is the number of elements in the array and \( k \) is the required number of ones in the binary representation.
The second line contains \( n \) space-separated integers representing the elements of the array.
outputFormat
Output a single integer, the count of elements whose binary representation has exactly \( k \) ones.
## sample5 2
3 5 6 7 8
3