CF1826B Lunatic Never Content
题目描述
现在有一个数组 $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$ 来代替。
说明/提示
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 $ .