Codeforces Round 736 (Div. 1)
B
Integers Have Friends
Codeforces
1800
原题
← AC →
翻译中…

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 $a_i, a_{i+1}, \ldots, a_j$ to be a friend group if and only if there exists an integer $m \ge 2$ such that $a_i \bmod m = a_{i+1} \bmod m = \ldots = a_j \bmod m$, where $x \bmod y$ denotes the remainder when $x$ is divided by $y$.

翻译中…

Your friend Gregor wants to know the size of the largest friend group in $a$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2\cdot 10^4$).

翻译中…

Each test case begins with a line containing the integer $n$ ($1 \le n \le 2 \cdot 10^5$), the size of the array $a$.

翻译中…

The next line contains $n$ positive integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le {10}^{18}$), 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\cdot 10^5$.

翻译中…

Output

翻译中…

Your output should consist of $t$ lines. Each line should consist of a single integer, the size of the largest friend group in $a$.

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #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
Output #1
3
3
2
6
InputCopy OutputCopy
题目信息
题号
1548B
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
分治
数学
数论
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。