1568 - Next K-Bit Number

Time Limit: 1s Memory Limit: 128MB

Submissions: 619 Solved: 226
Description
     Our problem is to create a function: uint NextKBitNumber(uint), which given an unsigned integer X with K bits set, returns the immediately larger unsigned integer also with K bits set. For example, if X = 12 (base 10) = 1100(base 2), X has 2 bits set, then  the next number with 2 bits set(NextKBitNumber) is 17(base 10) = 10001(base 2).
Input
      The first line is the number of test cases,there are at most 1001 cases.
      Then each line is a case with an unsigned  number X.
      It is guaranteed that all answers are in unsigned 32-bit Integer.
Output
      For each cases, the first line is “Case #k:”, where k is the case index based 1.
      The second line is  the NextKBitNumber of X.
Sample Input
2
12
7
Sample Output
Case #1:
17
Case #2:
11
Hint
Source
Yang WANG