Felix Felicis

4.6

5 votes
Bit manipulation, Easy
Problem

Harry needs to brew the Draught of Living Death perfectly in order to obtain a vile of Felix Felicis, also known as Liquid Luck.

Suppose Harry uses 'N' Sopophorous beans to brew this potion.

The cauldron needs to be stirred 'N & K' times ('&' represents bitwise AND) where 'K' is any non-negative integer strictly less than 'N'.

Among all the possible values of 'N & K', he must stir the potion the maximum number of times possible in order to brew the perfect potion, by selecting the appropriate value of K.

Help Harry find out the number of times he needs to stir the cauldron to brew the Draught of Living Death perfectly.

Input:
The first line contains a single integer 'T' denoting the number of test cases.
For each test case, a single line contains integer 'N' denoting number of beans used.

Output:
For each test case, print the number of times Harry needs to stir the cauldron to brew the perfect potion in a new line

Constraints:
1 <= T <= 10^6
1 <= N <= 10^9

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For N=5, we can take K = 0, 1, 2, 3, 4
Among these values, the max. value of N&K is obtained when K=4 :
5&4 = (101) & (100) = (100) = 4
So the answer is 4.

Editor Image

?