CF1794B.Not Dividing
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of n positive integers a1,a2,…,an. In one operation, you can choose any number of the array and add 1 to it.
Make at most 2n operations so that the array satisfies the following property: ai+1 is not divisible by ai, for each i=1,2,…,n−1.
You do not need to minimize the number of operations.
给你一个包含 n 个正整数的数组 a1,a2,…,an。在一次操作中,你可以任选数组中的一个数,并将其加 1。
请在至多 2n 次操作内,使数组满足如下性质:对每个 i=1,2,…,n−1,均有 ai+1 不被 ai 整除。
你无需最小化操作次数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤104) — the length of the given array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the given array.
It is guaranteed that the sum of n over all test cases does not exceed 5⋅104.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤104)—— 给定数组的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 给定的数组。
保证所有测试用例中 n 的总和不超过 5⋅104。
输出格式
For each test case, print the answer on a separate line.
In the only line, print n integers — the resulting array a after applying at most 2n operations.
We can show that an answer always exists under the given constraints. If there are multiple answers, print any of them.
对于每个测试用例,在单独的一行上输出答案。
在唯一的一行中,输出 n 个整数——即最多执行 2n 次操作后得到的数组 a。
在给定约束条件下,可以证明答案总是存在的。如果存在多个答案,输出其中任意一个即可。
输入输出样例
输入#1
3 4 2 4 3 6 3 1 2 3 2 4 2
输出#1
4 5 6 7 3 2 3 4 2
说明/提示
In the first test case, the array [4,5,6,7] can be achieved by applying 2 operations to the first element, 1 operation to the second element, 3 operations to the third element, and 1 operation to the last element. The total number of operations performed is 7, which is less than the allowed 8 operations in this case.
In the second test case, the array [3,2,3] can be achieved by applying two operations to the first element. Another possible resulting array could be [2,3,5], because the total number of operations does not need to be minimum.
In the third test case, not applying any operations results in an array that satisfies the statement's property. Observe that it is not mandatory to make operations.
在第一个测试用例中,数组 [4,5,6,7] 可通过以下方式得到:对第一个元素执行 2 次操作,对第二个元素执行 1 次操作,对第三个元素执行 3 次操作,对最后一个元素执行 1 次操作。总共执行的操作次数为 7,小于本例中允许的 8 次操作。
在第二个测试用例中,数组 [3,2,3] 可通过对第一个元素执行两次操作得到。另一个可能的最终数组是 [2,3,5],因为操作总次数无需达到最小值。
在第三个测试用例中,不执行任何操作即可得到满足题目所述性质的数组。注意:执行操作并非强制要求。
输入解题思路,AI测评打分。不知道怎么写?