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 aa of distinct positive integers.

Define a subarray ai,ai+1,,aja_i, a_{i+1}, \ldots, a_j to be a friend group if and only if there exists an integer m2m \ge 2 such that aimodm=ai+1modm==ajmodma_i \bmod m = a_{i+1} \bmod m = \ldots = a_j \bmod m , where xmodyx \bmod y denotes the remainder when xx is divided by yy .

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

输入格式

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

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

The next line contains nn positive integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai10181 \le a_i \le {10}^{18} ), representing the contents of the array aa . It is guaranteed that all the numbers in aa are distinct.

It is guaranteed that the sum of nn over all test cases is less than 21052\cdot 10^5 .

输出格式

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

输入输出样例

  • 输入#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][1,5,2,4,6] . The largest friend group is [2,4,6][2,4,6] , since all those numbers are congruent to 00 modulo 22 , so m=2m=2 .

In the second test case, the array is [8,2,5,10][8,2,5,10] . The largest friend group is [8,2,5][8,2,5] , since all those numbers are congruent to 22 modulo 33 , so m=3m=3 .

In the third case, the largest friend group is [1000,2000][1000,2000] . There are clearly many possible values of mm that work.

首页