CF2167D.Yet Another Array Problem

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Yet Another Array Problem

You are given an integer nn and an array aa of length nn.

Find the smallest integer xx (2≤x≤10182 \le x \le 10^{18}) such that there exists an index ii (1≤i≤n1 \le i \le n) with gcd⁡\gcd∗^{\text{∗}}(ai,x)=1(a_i, x) = 1. If no such xx exists within the range [2,1018][2,10^{18}], output −1-1.

∗^{\text{∗}}gcd⁡(x,y)\gcd(x, y) denotes the greatest common divisor (GCD) of integers xx and yy.

Input

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each of the following tt test cases consists of two lines:

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^{5}) — the length of the array.

The second line contains nn space-separated integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10181 \le a_i \le 10^{18}).

It is guaranteed that the total sum of nn across all test cases does not exceed 10510^{5}.

Output

For each test case, output a single integer: the smallest xx (2≤x≤10182 \le x \le 10^{18}) such that there exists an index ii with gcd⁡(ai,x)=1\gcd(a_i, x) = 1. If there is no such xx in the range [2,1018][2,10^{18}], print −1-1.

Note

In the first test case, gcd⁡(2,1)=1\gcd(2,1)=1, which is the smallest number satisfying the condition.

In the second test case:

  • gcd⁡(2,6)=2\gcd(2,6)=2, gcd⁡(2,12)=2\gcd(2,12)=2, so 22 cannot be the answer.
  • gcd⁡(3,6)=3\gcd(3,6)=3, gcd⁡(3,12)=3\gcd(3,12)=3, so 33 cannot be the answer.
  • gcd⁡(4,6)=2\gcd(4,6)=2, gcd⁡(4,12)=4\gcd(4,12)=4, so 44 cannot be the answer.
  • gcd⁡(5,6)=1\gcd(5,6)=1, so the answer is 55.

In the third test case:

  • gcd⁡(2,24)=2\gcd(2,24)=2, gcd⁡(2,120)=2\gcd(2,120)=2, gcd⁡(2,210)=2\gcd(2,210)=2, so 22 cannot be the answer.
  • gcd⁡(3,24)=3\gcd(3,24)=3, gcd⁡(3,120)=3\gcd(3,120)=3, gcd⁡(3,210)=3\gcd(3,210)=3, so 33 cannot be the answer.
  • gcd⁡(4,24)=4\gcd(4,24)=4, gcd⁡(4,120)=4\gcd(4,120)=4, gcd⁡(4,210)=2\gcd(4,210)=2, so 44 cannot be the answer.
  • gcd⁡(5,24)=1\gcd(5,24)=1, so the answer is 55.

In the fourth test case:

  • gcd⁡(2,2)=2\gcd(2,2)=2, gcd⁡(2,4)=2\gcd(2,4)=2, gcd⁡(2,6)=2\gcd(2,6)=2, gcd⁡(2,10)=2\gcd(2,10)=2, so 22 cannot be the answer.
  • gcd⁡(3,2)=1\gcd(3,2)=1, so the answer is 33.

Samples

4
1
1
4
6 6 12 12
3
24 120 210
4
2 4 6 10
2
5
5
3

在线编程 IDE

建议全屏模式获得最佳体验