CF1826B.Lunatic Never Content
普及/提高-
通过率:0%
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 .
输入格式
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 .
输出格式
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.
输入输出样例
输入#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 .