Refact.ai Match 1 (Codeforces Round 985)
E
Common Generator
Codeforces
2100
原题
← DF →
翻译中…

For two integers $x$ and $y$ ($x,y\ge 2$), we will say that $x$ is a generator of $y$ if and only if $x$ can be transformed to $y$ by performing the following operation some number of times (possibly zero):

翻译中…
  • Choose a divisor $d$ ($d\ge 2$) of $x$, then increase $x$ by $d$.
翻译中…

For example,

翻译中…
  • $3$ is a generator of $8$ since we can perform the following operations: $3 \xrightarrow{d = 3} 6 \xrightarrow{d = 2} 8$;
  • $4$ is a generator of $10$ since we can perform the following operations: $4 \xrightarrow{d = 4} 8 \xrightarrow{d = 2} 10$;
  • $5$ is not a generator of $6$ since we cannot transform $5$ into $6$ with the operation above.
翻译中…

Now, Kevin gives you an array $a$ consisting of $n$ pairwise distinct integers ($a_i\ge 2$).

翻译中…

You have to find an integer $x\ge 2$ such that for each $1\le i\le n$, $x$ is a generator of $a_i$, or determine that such an integer does not exist.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of the input contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. The description of test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1\le n\le 10^5$) — the length of the array $a$.

翻译中…

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($2\le a_i\le 4\cdot 10^5$) — the elements in the array $a$. It is guaranteed that the elements are pairwise distinct.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer $x$ — the integer you found. Print $-1$ if there does not exist a valid $x$.

翻译中…

If there are multiple answers, you may output any of them.

翻译中…

Note

翻译中…

In the first test case, for $x=2$:

翻译中…
  • $2$ is a generator of $8$, since we can perform the following operations: $2 \xrightarrow{d = 2} 4 \xrightarrow{d = 4} 8$;
  • $2$ is a generator of $9$, since we can perform the following operations: $2 \xrightarrow{d = 2} 4 \xrightarrow{d = 2} 6 \xrightarrow{d = 3} 9$.
  • $2$ is a generator of $10$, since we can perform the following operations: $2 \xrightarrow{d = 2} 4 \xrightarrow{d = 2} 6 \xrightarrow{d = 2} 8 \xrightarrow{d = 2} 10$.
翻译中…

In the second test case, it can be proven that it is impossible to find a common generator of the four integers.

翻译中…

样例

Input #1
4
3
8 9 10
4
2 3 4 5
2
147 154
5
3 6 8 25 100000
Output #1
2
-1
7
3
InputCopy OutputCopy
题目信息
题号
2029E
时间限制
2 s
内存限制
512 MB
标签
暴力
构造
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。