A coastal signal station transmits numeric codes to nearby ships. A code is considered "fully raised" when every bit of its binary representation is 1 -- that is, the codes 1, 11, 111, 1111, ... in binary, equal to 1, 3, 7, 15, 31, ... in decimal. Given a minimum required threshold n, find the smallest fully-raised code x such that x >= n.
A single line with one integer n.
A single integer: the smallest fully-raised code x with x >= n.
Example 1
Input
8
Expected
15
Explanation
The fully-raised codes in order are 1, 3, 7, 15, 31, .... The smallest one that is >= 8 is 15 (7 is too small), so the answer is 15.
Example 2
Input
1
Expected
1
Explanation
1 itself is fully-raised (its binary form is just "1") and 1 >= 1, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →