#C2981. Minimize Array Sum with Bitwise AND
Minimize Array Sum with Bitwise AND
Minimize Array Sum with Bitwise AND
You are given an array of n integers. You can perform the following operation repeatedly:
- Select any two elements from the array and replace them with their bitwise AND (denoted by
&
).
This process is repeated until only one element remains. Since the bitwise AND operation is both commutative and associative, the final remaining value is the bitwise AND of all the elements in the array. In mathematical notation, if the array is \(a_1, a_2, \ldots, a_n\), the final result is:
\[ a_1 \;\&\; a_2 \;\&\; \cdots \;\&\; a_n \]Your task is to compute this final value for each test case.
inputFormat
The first line contains a single 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 elements of the array.
All input should be read from stdin.
outputFormat
For each test case, output a single line containing the minimal possible value of the array achieved by performing the bitwise AND operation on all its elements.
Output should be written to stdout.
## sample2
3
1 3 5
4
12 15 7 9
1
0
</p>