#C13410. Numbers with k Set Bits
Numbers with k Set Bits
Numbers with k Set Bits
Given two integers (n) and (k), find all the distinct integers in the range ([0, 2^n - 1]) that have exactly (k) set bits in their binary representation. The numbers should be output in ascending order.
For example, when (n = 3) and (k = 2), the possible numbers are 3 (binary 011), 5 (binary 101), and 6 (binary 110).
inputFormat
The input consists of a single line containing two integers (n) and (k) separated by space, where (n) represents the number of bits and (k) represents the required number of set bits.
outputFormat
Output the numbers that have exactly (k) set bits in their binary representation in ascending order. The numbers should be printed in one line separated by a single space.## sample
3 2
3 5 6