DWITE Online Computer Programming Contest, January 2011, Problem 5
The binary weight of a number is the amount of
s in the number's binary representation. For example,
in binary is
, so the binary weight is
. Given a decimal number, we want to find the next greater decimal number that has the same binary weight. In this case,
(
) is such a number.
The input will contain 5 lines, integers
.
The output will contain 5 lines, each corresponding to the next decimal number with the same binary weight as in the input.
Reminder: a binary representation of a number is the sum of powers of
, where
means that power is included, and
means that it's not. So a binary
is
, which evaluates to
(
).
Sample Input
Copy
3
4
10
7
8
Sample Output
Copy
5
8
12
11
16
Problem Resource: DWITE
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
Comments
This problem is identical to this