CF1806F1.GCD Master (easy version)

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference between the two versions is the constraint on mm. You can make hacks only if both versions of the problem are solved.

You are given an array aa of length nn and two integers mm and kk. Each element in aa satisfies 1≤ai≤m1\le a_i \le m.

In one operation, you choose two indices ii and jj such that 1≤i<j≤∣a∣1 \le i \lt j \le |a|, then append gcd⁡(ai,aj)\gcd(a_i,a_j) to the back of the array and delete aia_i and aja_j from the array. Note that the length of the array decreases by one after this operation.

Find the maximum possible sum of the array after performing exactly kk operations.

这是该问题的简单版本。两个版本之间的唯一区别在于对 mm 的约束条件。仅当两个版本的问题均被解决时,你才可以进行 hack。

给定一个长度为 nn 的数组 aa 以及两个整数 mm 和 kk。数组 aa 中的每个元素均满足 1≤ai≤m1 \le a_i \le m。

在一次操作中,你需要选择两个下标 ii 和 jj,满足 1≤i<j≤∣a∣1 \le i < j \le |a|,然后将 gcd⁡(ai,aj)\gcd(a_i,a_j) 追加到数组末尾,并从数组中删除 aia_i 和 aja_j。注意:执行该操作后,数组长度减少 11。

求恰好执行 kk 次操作后,数组元素之和的最大可能值。

输入格式

The first line contains a single integer tt (1≤t≤1051\le t\le 10^5) — the number of test cases. The description of test cases follows.

The first line of each test case contains three integers nn, mm and kk (2≤n≤1062 \le n \le 10^6; 1≤m≤1061\le m \le 10^6; 1≤k≤n−11 \le k \le n-1).

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

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 and the sum of mm over all test cases does not exceed 10610^6.

第一行包含一个整数 tt(1≤t≤1051\le t\le 10^5)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(2≤n≤1062 \le n \le 10^6;1≤m≤1061\le m \le 10^6;1≤k≤n−11 \le k \le n-1)。

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

保证所有测试用例中 nn 的总和不超过 10610^6,且所有测试用例中 mm 的总和不超过 10610^6。

输出格式

For each test case, output the maximum possible sum of the array after performing kk operations optimally.

对于每个测试用例,输出执行 kk 次操作后数组可能达到的最大和。

输入输出样例

  • 输入#1

    3
    3 8 1
    4 7 8
    5 114 2
    7 2 4 1 6
    3 514 2
    2 3 3

    输出#1

    11
    14
    1

说明/提示

In the first test case, the best way is to choose i=1i=1, j=3j=3 in the first operation. The final sequence is [7,4][7,4].

在第一个测试用例中,最优方案是在第一次操作中选择 i=1i=1、j=3j=3。最终序列为 [7,4][7,4]。

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

首页