
maxBits
Given an integer n
, find the largest positive integer that has the same number of 0
s and 1
s in its binary representation.
Example
-
For
n = 5
, the output should bemaxBits(n) = 6
.5 = 1012
, so the answer is1102 = 6
. -
For
n = 15
, the output should bemaxBits(n) = 15
.15 = 11112
, so the answer is11112 = 15
.
Input/Output
-
[execution time limit] 0.5 seconds
-
[input] integer n
Constraints:
0 ≤ n ≤ 1000
-
[output] integer
- An integer that has as many 0s and 1s as
n
- An integer that has as many 0s and 1s as
Post Comment