CF1826B.Lunatic Never Content
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an array a of n non-negative integers. Let's define f(a,x)=[a1modx,a2modx,…,anmodx] for some positive integer x. Find the biggest x, such that f(a,x) is a palindrome.
Here, amodx 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≤i≤n) ai=an−i+1.
你有一个包含 n 个非负整数的数组 a。对某个正整数 x,定义函数 f(a,x)=[a1modx,a2modx,…,anmodx]。请找出最大的 x,使得 f(a,x) 是一个回文数组。
其中,amodx 表示 a 除以 x 所得的余数。
若一个数组正向读和反向读完全相同,则称其为回文数组。更严格地,长度为 n 的数组 a 是回文数组,当且仅当对每个 i(1≤i≤n)均有 ai=an−i+1。
输入格式
The first line contains a single integer t (1≤t≤105) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤105).
The second line of each test case contains n integers ai (0≤ai≤109).
It's guaranteed that the sum of all n does not exceed 105.
第一行包含一个整数 t(1≤t≤105),表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤105)。
每个测试用例的第二行包含 n 个整数 ai(0≤ai≤109)。
保证所有 n 的总和不超过 105。
输出格式
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.
对于每个测试用例,输出最大的 x,使得 f(a,x) 是一个回文数。如果 x 可以无限增大,则输出 0。
输入输出样例
输入#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] 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.
在第一个例子中,f(a,x=1)=[0,0],这是一个回文数列。
在第二个例子中,f(a,x=2)=[1,0,1,0,0,1,0,1],这是一个回文数列。
可以证明,在前两个例子中,不存在更大的 x 满足该条件。
在第三个例子中,对任意 x,均有 f(a,x)=[0],因此可选取任意大(即无上界),故答案为 0。
输入解题思路,AI测评打分。不知道怎么写?