#K38817. Bit Augmentation
Bit Augmentation
Bit Augmentation
You are given an array of n non-negative integers. You need to find the smallest integer \(X\) such that each element in the array can be increased to at least \(X\) by appending some bits to its binary representation. In other words, \(X\) is the smallest integer of the form \(2^k - 1\) (for some integer \(k\)) that is greater than or equal to the maximum element in the array.
For instance, consider an array [1, 3, 5]
. The maximum element is 5, and the smallest \(X\) of the form \(2^k - 1\) that satisfies \(X \geq 5\) is 7 (since \(7 = 2^3 - 1\)).
Note: The operations allowed simulate the process of adding bits to the binary representation, which effectively means finding the next \(2^k - 1\) number greater than the current maximum.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each test case is described as follows:
- The first line contains an integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
All input is provided via stdin
.
outputFormat
For each test case, output a single line containing the smallest integer \(X = 2^k - 1\) such that every element in the array can be made greater than or equal to \(X\). The output for all test cases should be printed on stdout
, with each result on a new line.
1
3
1 3 5
7
</p>