CF1826B.Lunatic Never Content

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

Here, amodxa \bmod x is the remainder of the integer division of aa by xx .

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

输入格式

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

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

The second line of each test case contains nn integers aia_i ( 0ai1090 \leq a_i \leq 10^9 ).

It's guaranteed that the sum of all nn does not exceed 10510^5 .

输出格式

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

输入输出样例

  • 输入#1

    4
    2
    1 2
    8
    3 0 1 2 0 3 2 1
    1
    0
    3
    100 1 1000000000

    输出#1

    1
    2
    0
    999999900

说明/提示

In the first example, f(a,x=1)=[0,0]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]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 xx satisfies the condition.

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

首页