CF1548B.Integers Have Friends
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends."
It turns out that positive integers can also be friends with each other! You are given an array a of distinct positive integers.
Define a subarray ai,ai+1,…,aj to be a friend group if and only if there exists an integer m≥2 such that aimodm=ai+1modm=…=ajmodm , where xmody denotes the remainder when x is divided by y .
Your friend Gregor wants to know the size of the largest friend group in a .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤2⋅104 ).
Each test case begins with a line containing the integer n ( 1≤n≤2⋅105 ), the size of the array a .
The next line contains n positive integers a1,a2,…,an ( 1≤ai≤1018 ), representing the contents of the array a . It is guaranteed that all the numbers in a are distinct.
It is guaranteed that the sum of n over all test cases is less than 2⋅105 .
输出格式
Your output should consist of t lines. Each line should consist of a single integer, the size of the largest friend group in a .
输入输出样例
输入#1
4 5 1 5 2 4 6 4 8 2 5 10 2 1000 2000 8 465 55 3 54 234 12 45 78
输出#1
3 3 2 6
说明/提示
In the first test case, the array is [1,5,2,4,6] . The largest friend group is [2,4,6] , since all those numbers are congruent to 0 modulo 2 , so m=2 .
In the second test case, the array is [8,2,5,10] . The largest friend group is [8,2,5] , since all those numbers are congruent to 2 modulo 3 , so m=3 .
In the third case, the largest friend group is [1000,2000] . There are clearly many possible values of m that work.