欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1780B.GCD Partition
GCD Partition
While at Kira's house, Josuke saw a piece of paper on the table with a task written on it.
The task sounded as follows. There is an array of length . On this array, do the following:
- select an integer ;
- split the array into subsegments ;
- calculate the sum in each of subsegments and write these sums to another array (where the sum of the subsegment is );
- the final score of such a split will be .
The task is to find such a partition that the score is maximum possible. Josuke is interested in this task but is not strong in computer science. Help him to find the maximum possible score.
A division of an array into subsegments is pairs of numbers such that and for every , also and . These pairs represent the subsegments.
stands for the greatest common divisor (GCD) of the array .
Input
The first line contains a single number () — the number of test cases.
For each test case, the first line contains one integer () — the length of the array .
The second line contains integers () — the array itself.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case print a single integer — the maximum score for the optimal partition.
Note
In the first test case, you can choose and split the array into subsegments and .
Then the score of such a partition will be equal to $\gcd(a_1 + a_2, a_3 + a_4) = \gcd(2 + 2, 1 + 3) = \gcd(4, 4) = 4$.
In the fourth test case, you can choose and split the array into subsegments .
The split score is .
Samples
6
4
2 2 1 3
2
1 2
3
1 4 5
6
1 2 1 1 1 3
10
12 30 37 88 12 78 89 17 2 12
6
7 7 7 7 7 7
4
1
5
3
1
21
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |