CF1731A.Joey Takes Money

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Joey is low on money. His friend Chandler wants to lend Joey some money, but can't give him directly, as Joey is too proud of himself to accept it. So, in order to trick him, Chandler asks Joey to play a game.

In this game, Chandler gives Joey an array a1,a2,…,ana_1, a_2, \dots, a_n (n≥2n \geq 2) of positive integers (ai≥1a_i \ge 1).

Joey can perform the following operation on the array any number of times:

  1. Take two indices ii and jj (1≤i<j≤n)1 \le i \lt j \le n).
  2. Choose two integers xx and yy (x,y≥1x, y \ge 1) such that x⋅y=ai⋅ajx \cdot y = a_i \cdot a_j.
  3. Replace aia_i by xx and aja_j by yy.

In the end, Joey will get the money equal to the sum of elements of the final array.

Find the maximum amount of money ans\mathrm{ans} Joey can get but print 2022⋅ans2022 \cdot \mathrm{ans}. Why multiplied by 20222022? Because we are never gonna see it again!

It is guaranteed that the product of all the elements of the array aa doesn't exceed 101210^{12}.

乔伊手头很紧。他的朋友钱德勒想借给乔伊一些钱,但又不能直接给他,因为乔伊太骄傲,不愿接受施舍。于是,为了“骗”他,钱德勒邀请乔伊玩一个游戏。

在这个游戏中,钱德勒给乔伊一个长度为 nn(n≥2n \geq 2)的正整数数组 a1,a2,…,ana_1, a_2, \dots, a_n(每个 ai≥1a_i \ge 1)。

乔伊可以对这个数组执行以下操作任意多次:

  1. 选取两个下标 ii 和 jj(满足 1≤i<j≤n1 \le i \lt j \le n);
  2. 选取两个正整数 xx 和 yy(即 x,y≥1x, y \ge 1),使得 x⋅y=ai⋅ajx \cdot y = a_i \cdot a_j;
  3. 将 aia_i 替换为 xx,同时将 aja_j 替换为 yy。

最终,乔伊获得的钱数等于最终数组中所有元素的和。

请找出乔伊能获得的最大金额 ans\mathrm{ans},但输出结果需为 2022⋅ans2022 \cdot \mathrm{ans}。为什么乘以 20222022?因为——我们再也不会见到它了!

保证数组 aa 中所有元素的乘积不超过 101210^{12}。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤40001 \leq t \leq 4000). Description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤502 \leq n \leq 50) — the length of the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061 \leq a_i \leq 10^6) — the array itself.

It's guaranteed that the product of all aia_i doesn't exceed 101210^{12} (i. e. a1⋅a2⋅…⋅an≤1012a_1 \cdot a_2 \cdot \ldots \cdot a_n \le 10^{12}).

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

每个测试用例的第一行包含一个整数 nn(2≤n≤502 \leq n \leq 50)—— 数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \leq a_i \leq 10^6)—— 数组本身。

保证所有 aia_i 的乘积不超过 101210^{12}(即 a1⋅a2⋅…⋅an≤1012a_1 \cdot a_2 \cdot \ldots \cdot a_n \le 10^{12})。

输出格式

For each test case, print the maximum money Joey can get multiplied by 20222022.

对于每个测试用例,输出 Joey 能获得的最大金额乘以 20222022 的结果。

输入输出样例

  • 输入#1

    3
    3
    2 3 2
    2
    1 3
    3
    1000000 1000000 1

    输出#1

    28308
    8088
    2022000000004044

说明/提示

In the first test case, Joey can do the following:

  1. He chooses i=1i = 1 and j=2j = 2 (so he has a[i]⋅a[j]=6a[i] \cdot a[j] = 6), chooses x=6x = 6 and y=1y = 1 and makes a[i]=6a[i] = 6 and a[j]=1a[j] = 1. $$[2, 3, 2] \xrightarrow[x = 6,\; y = 1]{i = 1,\; j = 2} [6, 1, 2]$$
  2. He chooses i=1i = 1 and j=3j = 3 (so he has a[i]⋅a[j]=12a[i] \cdot a[j] = 12), chooses x=12x = 12 and y=1y = 1 and makes a[i]=12a[i] = 12 and a[j]=1a[j] = 1. $$[6, 1, 2] \xrightarrow[x = 12,\; y = 1]{i = 1,\; j = 3} [12, 1, 1]$$

The sum is 1414 which is the maximum of all possible sums. The answer is 2022⋅14=283082022 \cdot 14 = 28308.

在第一个测试用例中,Joey 可以执行以下操作:

  1. 他选择 i=1i = 1 和 j=2j = 2(此时有 a[i]⋅a[j]=6a[i] \cdot a[j] = 6),再选择 x=6x = 6 和 y=1y = 1,并将 a[i]a[i] 修改为 66、a[j]a[j] 修改为 11。

[2,3,2]→i=1,  j=2x=6,  y=1[6,1,2][2, 3, 2] \xrightarrow[i = 1,\; j = 2]{x = 6,\; y = 1} [6, 1, 2]

  1. 他选择 i=1i = 1 和 j=3j = 3(此时有 a[i]⋅a[j]=12a[i] \cdot a[j] = 12),再选择 x=12x = 12 和 y=1y = 1,并将 a[i]a[i] 修改为 1212、a[j]a[j] 修改为 11。

[6,1,2]→i=1,  j=3x=12,  y=1[12,1,1][6, 1, 2] \xrightarrow[i = 1,\; j = 3]{x = 12,\; y = 1} [12, 1, 1]

此时数组元素之和为 1414,是所有可能方案中的最大值。答案为 2022⋅14=283082022 \cdot 14 = 28308。

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

首页