#t369. 蒟蒻的问题
蒟蒻的问题
The Next Integer with the Same Number of 1s
Problem Description
Given a positive integer , find the smallest positive integer greater than such that the binary representations of and contain the same number of s.
For example, given , its binary representation is , which contains ones. The smallest number greater than whose binary representation also contains exactly ones is (binary ), so is the answer.
Input Format
There are several lines of input. Each line contains one integer . Input ends with 0.
Output Format
For each input line, output the corresponding answer on its own line.
Sample Input
1
2
3
4
78
0
Sample Output
2
4
5
8
83
Hint
Source: ybt (一本通 online judge).