#K78077. Largest Number with Maximum Ones
Largest Number with Maximum Ones
Largest Number with Maximum Ones
Given a positive integer N, find the largest number less than or equal to N that has a binary representation consisting entirely of 1s. In mathematical terms, you are to find the maximum integer of the form \(2^m - 1\) (where m is a positive integer) which does not exceed N.
For example:
- For N = 5, the possible numbers of the form \(2^m - 1\) are 1 (binary 1), 3 (binary 11), 7 (binary 111). Since 7 > 5, the answer is 3.
- For N = 10, the answer is 7, because 7 (binary 111) is the largest number of that form that is \(\leq 10\).
This problem requires careful handling of input and output, as the solution should read from standard input and write to standard output.
inputFormat
The input consists of a single integer N (1 ≤ N ≤ 109 or as specified) read from standard input.
outputFormat
Output a single integer: the largest number less than or equal to N that can be represented as \(2^m - 1\) for some positive integer m.
## sample5
3