CF1826B.Lunatic Never Content

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array aa of nn non-negative integers. Let's define f(a,x)=[a1 mod x,a2 mod x,…,an mod x]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, a mod xa \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 (1≤i≤n1 \leq i \leq n) ai=an−i+1a_i = a_{n - i + 1}.

你有一个包含 nn 个非负整数的数组 aa。对某个正整数 xx,定义函数 f(a,x)=[a1 mod x,a2 mod x,…,an mod x]f(a, x) = [a_1 \bmod x, a_2 \bmod x, \dots, a_n \bmod x]。请找出最大的 xx,使得 f(a,x)f(a, x) 是一个回文数组。

其中,a mod xa \bmod x 表示 aa 除以 xx 所得的余数。

若一个数组正向读和反向读完全相同,则称其为回文数组。更严格地,长度为 nn 的数组 aa 是回文数组,当且仅当对每个 ii(1≤i≤n1 \leq i \leq n)均有 ai=an−i+1a_i = a_{n - i + 1}。

输入格式

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

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

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

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

第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。

每个测试用例的第二行包含 nn 个整数 aia_i(0≤ai≤1090 \leq a_i \leq 10^9)。

保证所有 nn 的总和不超过 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.

对于每个测试用例,输出最大的 xx,使得 f(a,x)f(a, x) 是一个回文数。如果 xx 可以无限增大,则输出 00。

输入输出样例

  • 输入#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.

在第一个例子中,f(a,x=1)=[0,0]f(a, x = 1) = [0, 0],这是一个回文数列。

在第二个例子中,f(a,x=2)=[1,0,1,0,0,1,0,1]f(a, x = 2) = [1, 0, 1, 0, 0, 1, 0, 1],这是一个回文数列。

可以证明,在前两个例子中,不存在更大的 xx 满足该条件。

在第三个例子中,对任意 xx,均有 f(a,x)=[0]f(a, x) = [0],因此可选取任意大(即无上界),故答案为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页