DWITE '10 R4 #3 - Binary Weight

View as PDF

Points: 5
Time limit: 0.1s
Memory limit: 64M

Problem type
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

3
4
10
7
8

Sample Output

5
8
12
11
16

Problem Resource: DWITE

• commented on Aug. 19, 2020, 7:20 p.m. edit 3

can someone pls give me tips on how to make my code run faster?

• commented on Aug. 19, 2020, 8:25 p.m.

Your complexity is too slow, consider asking your code nicely to run faster or observe what happens with the binary representations of the numbers.