CF2258A.Odd Eraser

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an array a1,a2,…,ana_1, a_2, \ldots, a_n, you can apply the following operation any number of times (possibly zero):

  • Choose an integer k≥1k \geq 1 such that 2k+1≤m2k+1 \le m and 2k+12k+1 indices, i1,i2,…,i2k+1i_1, i_2, \ldots, i_{2k+1} (1≤i1<i2<…<i2k+1≤m1 \le i_1 \lt i_2 \lt \ldots \lt i_{2k+1} \le m), where mm is the current length of the array. Then, remove the ik+1i_{k+1}-th element from the array.

Note that after any operation, the length of the array is reduced by one, and the rest of the array is concatenated.

Let b1,b2,…,bmb_1, b_2, \ldots, b_m be the remaining array after all operations.

What is the maximum possible value of gcd⁡(b1,b2,…,bm)\gcd(b_1, b_2, \ldots, b_m), where gcd⁡\gcd of an array of integers denotes the greatest common divisor (GCD) of them?

给定一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n,你可以执行以下操作任意多次(也可以不执行):

  • 选择一个整数 k≥1k \geq 1,使得 2k+1≤m2k+1 \le m,并选择 2k+12k+1 个下标 i1,i2,…,i2k+1i_1, i_2, \ldots, i_{2k+1}(满足 1≤i1<i2<…<i2k+1≤m1 \le i_1 \lt i_2 \lt \ldots \lt i_{2k+1} \le m),其中 mm 是当前数组的长度。然后,将数组中第 ik+1i_{k+1} 个元素删除。

注意:每次操作后,数组长度减少 1,其余元素保持顺序拼接。

设所有操作结束后剩余的数组为 b1,b2,…,bmb_1, b_2, \ldots, b_m。

那么 gcd⁡(b1,b2,…,bm)\gcd(b_1, b_2, \ldots, b_m) 的最大可能值是多少?其中 gcd⁡\gcd 表示该整数数组的最大公约数(GCD)。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains nn (1≤n≤1001 \le n \le 100), denoting the size of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是测试用例的描述。

每个测试用例的第一行包含 nn(1≤n≤1001 \le n \le 100),表示数组的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

输出格式

For each test case, output a single integer — the maximum possible value.

对于每个测试用例,输出一个整数——最大可能的值。

输入输出样例

  • 输入#1

    4
    7
    2 4 6 7 8 9 10
    2
    55 55555
    4
    1000000 1000 1 1000000000
    5
    23 32 23 32 23

    输出#1

    2
    5
    1000000
    23

说明/提示

In the first test case, the given array is [2,4,6,7,8,9,10][2, 4, 6, 7, 8, 9, 10].

Choosing indices [1,3,4,6,7][1, 3, 4, 6, 7] results in the removal of a4=7a_4 = 7 and the array [2,4,6,8,9,10][2, 4, 6, 8, 9, 10].

Then, choosing indices [2,5,6][2, 5, 6] results in the removal of a5=9a_5 = 9 and the array [2,4,6,8,10][2, 4, 6, 8, 10]. You can't get an answer greater than 22.

在第一个测试用例中,给定的数组为 [2,4,6,7,8,9,10][2, 4, 6, 7, 8, 9, 10]。

选择下标 [1,3,4,6,7][1, 3, 4, 6, 7],将移除 a4=7a_4 = 7,得到数组 [2,4,6,8,9,10][2, 4, 6, 8, 9, 10]。

接着,选择下标 [2,5,6][2, 5, 6],将移除 a5=9a_5 = 9,得到数组 [2,4,6,8,10][2, 4, 6, 8, 10]。你无法得到大于 22 的答案。

输入解题思路,AI测评打分。不知道怎么写?

首页