310388: CF1826B. Lunatic Never Content

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Lunatic Never Contenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have an array $a$ of $n$ non-negative integers. Let's define $f(a, x) = [a_1 \bmod x, a_2 \bmod x, \dots, a_n \bmod x]$ for some positive integer $x$. Find the biggest $x$, such that $f(a, x)$ is a palindrome.

Here, $a \bmod x$ is the remainder of the integer division of $a$ by $x$.

An array is a palindrome if it reads the same backward as forward. More formally, an array $a$ of length $n$ is a palindrome if for every $i$ ($1 \leq i \leq n$) $a_i = a_{n - i + 1}$.

Input

The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$).

The second line of each test case contains $n$ integers $a_i$ ($0 \leq a_i \leq 10^9$).

It's guaranteed that the sum of all $n$ does not exceed $10^5$.

Output

For each test case output the biggest $x$, such that $f(a, x)$ is a palindrome. If $x$ can be infinitely large, output $0$ instead.

ExampleInput
4
2
1 2
8
3 0 1 2 0 3 2 1
1
0
3
100 1 1000000000
Output
1
2
0
999999900
Note

In the first example, $f(a, x = 1) = [0, 0]$ which is a palindrome.

In the second example, $f(a, x = 2) = [1, 0, 1, 0, 0, 1, 0, 1]$ which is a palindrome.

It can be proven that in the first two examples, no larger $x$ satisfies the condition.

In the third example, $f(a, x) = [0]$ for any $x$, so we can choose it infinitely large, so the answer is $0$.

Input

题意翻译

**题目描述** 现在有一个数组 $a$,和 $n$ 个非负整数,定义 $f(a,x)=[a_1\bmod x,a_2\bmod x,\dots,a_n\bmod x]$,其中 $x$ 为正整数。现要你找到最大的 $x$,使得 $f(a,x)$ 是回文的。 这里,$a \bmod x$ 的含义为 $a$ 除以 $x$ 得到的余数。 我们认为一个数组是回文的,当且仅当从前往后读得到的结果和从后往前读得到的结果完全相同。换句话说,一个长度为 $n$ 的数组 $a$ 是回文的,当且仅当 $\forall 1\leq i \leq n$,有 $a_i=a_{n-i+1}$。 **输入格式** 第一行一个整数 $t(1 \leq t \leq 10^5)$,代表测试数据的组数。 对于每一组测试数据: 第一行一个整数 $n(1 \leq n \leq 10^5)$,代表数组 $a$ 的长度。 第二行共 $n$ 个数,以空格隔开,对于 $1\leq i \leq n$,第 $i$ 个数代表 $a_i$。 数据保证 $\sum n \leq 10^5$。 **输出格式** 对于每一组测试用例,输出最大的 $x$ ,使得 $f(a,x)$ 是回文的。如果 $x$ 可以为无穷大,输出 $0$ 来代替。

Output

题目大意:
你有一个由非负整数组成的数组a。定义f(a, x) = [a_1 % x, a_2 % x, ..., a_n % x],对于某个正整数x。找出最大的x,使得f(a, x)是一个回文数。

输入数据格式:
第一行包含一个整数t(1≤t≤10^5)——测试用例的数量。
每个测试用例的第一行包含一个整数n(1≤n≤10^5)。
每个测试用例的第二行包含n个整数a_i(0≤a_i≤10^9)。
保证所有n的总和不超过10^5。

输出数据格式:
对于每个测试用例输出最大的x,使得f(a, x)是一个回文数。如果x可以无限大,则输出0。题目大意: 你有一个由非负整数组成的数组a。定义f(a, x) = [a_1 % x, a_2 % x, ..., a_n % x],对于某个正整数x。找出最大的x,使得f(a, x)是一个回文数。 输入数据格式: 第一行包含一个整数t(1≤t≤10^5)——测试用例的数量。 每个测试用例的第一行包含一个整数n(1≤n≤10^5)。 每个测试用例的第二行包含n个整数a_i(0≤a_i≤10^9)。 保证所有n的总和不超过10^5。 输出数据格式: 对于每个测试用例输出最大的x,使得f(a, x)是一个回文数。如果x可以无限大,则输出0。

加入题单

上一题 下一题 算法标签: