Joey 很穷,因此他的朋友 Chandler 想要借给他一些钱。但是 Joey 的自尊心很强,为了不让他的自尊心受挫又能给他钱,Chandler 打算和他玩一个游戏。
在这个游戏中,Chandler 会给 Joey 一个数组 a 1 , a 2 , … , a n ( n ≥ 2 , a i ∈ Z + ) a_1,a_2,\dots,a_n(n\ge 2,a_i \in \mathbb{Z^+}) a1,a2,…,an(n≥2,ai∈Z+)。Joey 可以对这个数组进行如下的操作任意次:
最后, Joey 将得到的钱就是 a a a 数组中所有值的和。即 Joey 所得的钱 = ∑ i = 1 n a i = \sum^{n}_{i=1}a_{i} =∑i=1nai .
你需要求出一个整数 a n s ans ans,即 Joey 最多可以得到的钱,并输出 2022 ⋅ a n s 2022 \cdot ans 2022⋅ans 。为什么要乘以 2022 2022 2022 呢?因为我们再也见不到它了!(悲)
输入数据保证 a a a 数组内所有数的乘积不超过 1 0 12 10^{12} 1012,即 ∏ i = 1 n a i ≤ 1 0 12 \prod^{n}_{i=1}a_{i} \le 10^{12} ∏i=1nai≤1012.
输入包含多组测试数据。
共一行,一个整数,表示 Joey 最多可以得到的钱乘以 2022 后的值。
在测试样例的第一组测试数据中,Joey 可以这么做:
综上所述, Joey 可以得到的最多的钱即为 12 + 1 + 1 = 14 12+1+1=14 12+1+1=14 元,所以输出应为 14 × 2022 = 28308 14\times 2022 = 28308 14×2022=28308.
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 $ a_1, a_2, \dots, a_n $ ( $ n \geq 2 $ ) of positive integers ( $ a_i \ge 1 $ ).
Joey can perform the following operation on the array any number of times:
In the end, Joey will get the money equal to the sum of elements of the final array.
Find the maximum amount of money $ \mathrm{ans} $ Joey can get but print $ 2022 \cdot \mathrm{ans} $ . Why multiplied by $ 2022 $ ? Because we are never gonna see it again!
It is guaranteed that the product of all the elements of the array $ a $ doesn’t exceed $ 10^{12} $ .
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \leq t \leq 4000 $ ). Description of the test cases follows.
The first line of each test case contains a single integer $ n $ ( $ 2 \leq n \leq 50 $ ) — the length of the array $ a $ .
The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \leq a_i \leq 10^6 $ ) — the array itself.
It’s guaranteed that the product of all $ a_i $ doesn’t exceed $ 10^{12} $ (i. e. $ a_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 $ 2022 $ .
3
3
2 3 2
2
1 3
3
1000000 1000000 1
28308
8088
2022000000004044
In the first test case, Joey can do the following:
采用贪心的思想,计算每一个数字的连乘,并放到第一个位置,其他位置为1,此时可以达到最大
//
// Created by Gowi on 2023/12/2.
//
#include
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, s = 1;
cin >> n;
for (int i = 0; i < n; ++i) {
long long a;
cin >> a;
s *= a;
}
s = s + n - 1;
cout << 2022 * s << endl;
}
}