CF1806F1.GCD Master (easy version)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The only difference between the two versions is the constraint on m . You can make hacks only if both versions of the problem are solved.
You are given an array a of length n and two integers m and k . Each element in a satisfies 1≤ai≤m .
In one operation, you choose two indices i and j such that 1≤i<j≤∣a∣ , then append gcd(ai,aj) to the back of the array and delete ai and aj 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 k operations.
输入格式
The first line contains a single integer t ( 1≤t≤105 ) — the number of test cases. The description of test cases follows.
The first line of each test case contains three integers n , m and k ( 2≤n≤106 ; 1≤m≤106 ; 1≤k≤n−1 ).
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤m ).
It is guaranteed that the sum of n over all test cases does not exceed 106 and the sum of m over all test cases does not exceed 106 .
输出格式
For each test case, output the maximum possible sum of the array after performing k operations optimally.
输入输出样例
输入#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=1 , j=3 in the first operation. The final sequence is [7,4] .