Problem 3810 --Integers Have Friends 2.0

3810: Integers Have Friends 2.0

"
Time Limit $3$ 秒/Second(s) Memory Limit $128$ 兆字节/Megabyte(s)
提交总数 $0$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Acknowledgment: Special thanks to Codeforces Problem 1548B Integer Have Friends for providing the general statement for this problem.

Indian mathematician Srinivasa Ramanujan once quoted the famous words of 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 subsequence ac1,ac2,…,ack where k≥1 and 1≤c1<c2<⋯<ck≤n to be a friend group if and only if there exists an integer m≥2 such that ac1 mod m=ac2 mod m=⋯=ack mod m, where x mod y denotes the remainder when x is divided by y.

Your friend gispzjz wants to know the size of the largest friend group in a. Can you help him?
The first line contains a number T(1≤T≤30), denoting the number of test cases.

The first line of each test case contains one integer n(2≤n≤2×105), denoting the size of the array a.

Then one line containing n integers a1,a2,…,an(1≤ai≤4×1012) follow, representing the contents of the array aIt is guaranteed that all the numbers in a are distinct.

It is guaranteed that ∑n≤106 over all test cases.
For each test case, output a line consisting of a single integer, denoting the size of the largest friend group in a.
3
3
10 12 15
4
4 6 9 19
6
2 8 11 15 19 38
2
3
4

推荐代码 查看3810 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战

赛题来源/所属竞赛 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛