DWITE '11 R5 #5 - Binary Weight

View as PDF

Submit solution

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

Problem type
DWITE Online Computer Programming Contest, January 2011, Problem 5

The binary weight of a number is the amount of 1s in the number's binary representation. For example, 43 in binary is 101011, so the binary weight is 4. Given a decimal number, we want to find the next greater decimal number that has the same binary weight. In this case, 45 (101101) is such a number.

The input will contain 5 lines, integers 1N1000000000.

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 2, where 1 means that power is included, and 0 means that it's not. So a binary 43 is 1×25+0×24+1×23+0×22+1×21+1×20, which evaluates to 1×32+0×16+1×8+0×4+1×2+1×2=32+8+2+1=43 (101011).

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


  • 3
    max  commented on April 11, 2018, 9:54 a.m. edited

    This problem is identical to this