CF1548B.Integers Have Friends
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
英国数学家约翰·利特尔伍德曾这样评价印度数学家斯里尼瓦萨·拉马努金:“每一个正整数都是他的私人朋友。”
事实上,正整数之间也可以成为朋友!你将得到一个由互不相同的正整数组成的数组 a。
定义子数组 ai,ai+1,…,aj 为一个朋友组,当且仅当存在某个整数 m≥2,使得
aimodm=ai+1modm=…=ajmodm,
其中 xmody 表示 x 除以 y 所得的余数。
你的朋友格雷戈尔想知道数组 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.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤2⋅104)。
每个测试用例以一行开始,该行包含整数 n(1≤n≤2⋅105),表示数组 a 的大小。
下一行包含 n 个正整数 a1,a2,…,an(1≤ai≤1018),表示数组 a 的内容。保证数组 a 中的所有数字互不相同。
保证所有测试用例的 n 之和小于 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.
你的输出应包含 t 行。每行应为一个整数,表示数组 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.
在第一个测试用例中,数组为 [1,5,2,4,6]。最大的朋友组是 [2,4,6],因为这些数对模 2 同余(即余数均为 0),故 m=2。
在第二个测试用例中,数组为 [8,2,5,10]。最大的朋友组是 [8,2,5],因为这些数对模 3 同余(即余数均为 2),故 m=3。
在第三个测试用例中,最大的朋友组是 [1000,2000]。显然存在许多满足条件的 m 值。
输入解题思路,AI测评打分。不知道怎么写?