#K86947. Largest Binary Ones

    ID: 36977 Type: Default 1000ms 256MiB

Largest Binary Ones

Largest Binary Ones

You are given a positive integer n. Your task is to find the largest integer x such that x ≤ n and the binary representation of x is composed entirely of the digit '1'.

For example, when n = 5, the possible candidates are 1 (binary 1), 3 (binary 11) and 7 (binary 111) but since 7 > 5, the answer is 3. Similarly, for n = 13, the answer is 7, and for n = 30, the answer is 15.

Hint: The numbers composed only of 1's in binary are of the form \(2^k - 1\) for some integer \(k\geq1\).

inputFormat

The first line of input contains a single integer T representing the number of test cases. Each of the next T lines contains one integer n.

Input Format: T n1 n2 ... nT

outputFormat

For each test case, output a single integer in a separate line: the largest integer less than or equal to n whose binary representation consists only of '1's.

Output Format: x1 x2 ... xT

## sample
3
5
13
30
3

7 15

</p>