Codeforces Round 1045 (Div. 2)

Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
2134 Codeforces Round 1045 (Div. 2) FINISHED False 7200 20186723 Aug. 26, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 20750 ) B Add 0 or K PROGRAMMING constructive algorithms math number theory

You are given an array of (n) positive integers (a_1, a_2, \ldots, a_n) and a positive integer (k). In one operation, you may add either (0) or (k) to each (a_i), i.e., choose another array of (n) integers (b_1, b_2, \ldots, b_n) where each (b_i) is either (0) or (k), and update (a_i) to (a_i + b_i) for (1 \le i \le n). Note that you can choose different values for each element of the array (b). Your task is to perform at most (k) such operations to make (\gcd(a_1, a_2, \ldots, a_n) > 1) (^{\text{∗}}). It can be proved that this is always possible. Output the final array after the operations. You do not have to output the operations themselves. (^{\text{∗}})(\gcd(a_1, a_2, \ldots, a_n)) denotes the greatest common divisor (GCD) of (a_1, a_2, \ldots, a_n). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 1000)). The description of the test cases follows. The first line of each test case contains two integers (n) and (k) ((1 \le n \le 10^5), (1 \leq k \leq 10^9)) — the length of the array (a) and the given constant. The second line of each test case contains (n) integers (a_1,a_2,\ldots,a_n) ((1 \le a_i \le 10^9)) — the elements of the array (a). It is guaranteed that the sum of (n) over all test cases does not exceed (10^5). For each test case, output an array of (n) integers in a new line — the final array after the operations. The integers in the output should be within the range from (1) to (10^9 + k^2). If there are multiple valid outputs, you can output any of them. Note that you do not have to minimize the number of operations. In the first test case, the output (8,10,10) is valid because (\gcd(8, 10, 10) = 2 > 1), and the array (2, 7, 1) can be transformed into (8, 10, 10) using at most (3) operations. One possible sequenc

Tutorials

145832

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
335756078 Mohan_Patel B Aug. 27, 2025, 5:56 a.m. OK C# 10 TESTS 12 233 14233600
335700108 kaifonaft B Aug. 26, 2025, 4:32 p.m. OK C# 10 TESTS 10 280 10854400
335711674 og.kostya B Aug. 26, 2025, 5:57 p.m. OK C# 13 TESTS 10 155 4812800

remove filters

Back to search problems