⠀
You are given an array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an of distinct positive integers. You have to do the following operation exactly once:
- choose a positive integer k k k;
- for each i i i from 1 1 1 to n n n, replace a i a_i ai with a i mod k † a_i \text{ mod } k^\dagger ai mod k†.
Find a value of k k k such that 1 ≤ k ≤ 1 0 18 1 \leq k \leq 10^{18} 1≤k≤1018 and the array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an contains exactly 2 2 2 distinct values at the end of the operation. It can be shown that, under the constraints of the problem, at least one such k k k always exists. If there are multiple solutions, you can print any of them.
† ^\dagger † a mod b a \text{ mod } b a mod b denotes the remainder after dividing a a a by b b b. For example:
- 7 mod 3 = 1 7 \text{ mod } 3=1 7 mod 3=1 since 7 = 3 ⋅ 2 + 1 7 = 3 \cdot 2 + 1 7=3⋅2+1
- 15 mod 4 = 3 15 \text{ mod } 4=3 15 mod 4=3 since 15 = 4 ⋅ 3 + 3 15 = 4 \cdot 3 + 3 15=4⋅3+3
- 21 mod 1 = 0 21 \text{ mod } 1=0 21 mod 1=0 since 7 = 7 ⋅ 1 + 0 7 = 7 \cdot 1 + 0 7=7⋅1+0
- Input
Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 500 1 \le t \le 500 1≤t≤500). The description of the test cases follows.
The first line of each test case contains a single integer n n n ( 2 ≤ n ≤ 100 2 \le n \le 100 2≤n≤100) — the length of the array a a a.
The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 17 1 \le a_i \le 10^{17} 1≤ai≤1017) — the initial state of the array. It is guaranteed that all the a i a_i ai are distinct.
Note that there are no constraints on the sum of
n
n
n over all test cases.
Output
For each test case, output a single integer: a value of k k k ( 1 ≤ k ≤ 1 0 18 1 \leq k \leq 10^{18} 1≤k≤1018) such that the array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an contains exactly 2 2 2 distinct values at the end of the operation.
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
typedef long long LL;
LL f[N];
int n;
int main()
{
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 0; i < n; i++) cin >> f[i];
LL k = 1;
while (1)
{
set<LL> s;
for (int i = 0; i < n; i++)s.insert(f[i] % k);
if (s.size() == 2)
{
cout << k << endl;
break;
}
k *= 2;
}
}
}