题库练习 Min Or Sum
← 上一题 下一题 →

A14772 | Min Or Sum

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given an array $a$ of size $n$ .

You can perform the following operation on the array:

- Choose two different integers $i, j$ $(1 \leq i < j \leq n$ ), replace $a_i$ with $x$ and $a_j$ with $y$ . In order not to break the array, $a_i | a_j = x | y$ must be held, where $|$ denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). Notice that $x$ and $y$ are non-negative integers.

Please output the minimum sum of the array you can get after using the operation above any number of times.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $t$ $(1 \leq t \leq 1000)$ . Description of the test cases follows.

The first line of each test case contains an integer $n$ $(2 \leq n \leq 100)$ — the size of array $a$ .

The second line of each test case contains $n$ integers $a_1, a_2, \ldots ,a_n$ $(0 \leq a_i < 2^{30})$ .

输出格式

For each test case, print one number in a line — the minimum possible sum of the array.

输入输出样例

输入 #1
4
3
1 3 2
5
1 2 4 8 16
2
6 6
3
3 5 6
输出 #1
3
31
6
7
C++ 编辑器
输入
输出