Huawei OD computer test - finding numbers (Java & JS & Python & C)

Question description

Xiaofan and Xiaozhou played the numbers game again today.

The boat gives the fan a positive integer n (1 ≤ n ≤ 1e9). The fan needs to find a number m that is larger than n, so that the number of 1's in the binary system corresponding to m and n must be the same, such as:

4 corresponds to 100 in binary

8 corresponds to 1000 in binary

The number of 1's is 1

Now find the minimum value of m.

Enter description

Enter a positive integer n (1 ≤ n ≤ 1e9)

Output description

Output a positive integer m

Example

enter 2
output 4
illustrate

2 binary 10,

The binary digit of 4 is 100,

The number of 1 is the same, and 4 is the smallest number that satisfies the condition

Guess you like

Origin blog.csdn.net/qfc_128220/article/details/134867943