DWITE Online Computer Programming Contest, January 2011, Problem 3
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
can someone pls give me tips on how to make my code run faster?
Your complexity is too slow, consider asking your code nicely to run faster or observe what happens with the binary representations of the numbers.