Codeforces Round 1060 (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
2154 Codeforces Round 1060 (Div. 2) FINISHED False 7200 19495487 Oct. 19, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 5590 ) C2 No Cost Too Great (Hard Version) PROGRAMMING greedy math number theory

This is the hard version of the problem. The difference between the versions is that in this version, (1 \le b_i \le 10^9) for all (i) ((1 \le i \le n)). You can hack only if you solved all versions of this problem. You find yourself with two arrays of positive integers (a) and (b), both of length (n). You will perform the following operation any number of times (possibly none): select an integer (i) ((1 \le i \le n)) and increase (a_i) by (1). This has a cost of (b_i). Determine the minimum total cost to make it so that there exists two integers (i, j) where (1 \le i < j \le n) and (\gcd(a_i, a_j))(^{\text{∗}})(> 1). (^{\text{∗}})(\gcd(x, y)) denotes the greatest common divisor (GCD) of integers (x) and (y). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each testcase contains an integer (n) ((2 \le n \le 2 \cdot 10^5)) — the length of the array (a). The second line of each testcase contains (n) integers (a_1,a_2,\ldots,a_n) ((1 \le a_i \le 2 \cdot 10^5)). The third line of each testcase contains (n) integers (b_1,b_2,\ldots,b_n) ((\color{red}{1 \le b_i \le 10^9})). The sum of (n) across all testcases does not exceed (2 \cdot 10^5). For each testcase, output the minimum cost. In the first testcase we can do the following: (\color{red}1, 1 \xrightarrow{x = 1} 2, \color{red}1 \xrightarrow{x = 2} 2, 2), this has cost (1 + 2 = 3). Now (\gcd(a_1, a_2) = \gcd(2, 2) = 2) and so (\gcd(a_1, a_2) > 1). It can be proven that this is the minimum cost required. In the second testcase it is already true that (\gcd(a_1, a_2) = 4) and so (\gcd(a_1, a_2) > 1). So no operations are required.

Tutorials

Codeforces Round 1060 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
344751507 Yugi.Hacker C2 Oct. 19, 2025, 5:36 p.m. OK C++17 (GCC 7-32) TESTS 21 171 1638400
344803594 kulkarnichaitanya665 C2 Oct. 20, 2025, 4:36 a.m. OK C++17 (GCC 7-32) TESTS 29 202 0
344800546 Feng5u C2 Oct. 20, 2025, 3:54 a.m. OK C++17 (GCC 7-32) TESTS 29 218 102400
344792156 fried-chicken C2 Oct. 20, 2025, 1:51 a.m. OK C++17 (GCC 7-32) TESTS 29 218 30924800
344798735 waiting2050 C2 Oct. 20, 2025, 3:29 a.m. OK C++17 (GCC 7-32) TESTS 29 234 5632000
344752989 Roga_Manush C2 Oct. 19, 2025, 5:43 p.m. OK C++17 (GCC 7-32) TESTS 21 249 3276800
344805609 _Z0R0_ C2 Oct. 20, 2025, 5:01 a.m. OK C++17 (GCC 7-32) TESTS 29 249 3584000
344766083 mmestrovic C2 Oct. 19, 2025, 7 p.m. OK C++17 (GCC 7-32) TESTS 24 249 7168000
344791743 eirinayukari C2 Oct. 20, 2025, 1:44 a.m. OK C++17 (GCC 7-32) TESTS 29 250 3276800
344779838 pranabmishra2602 C2 Oct. 19, 2025, 9:24 p.m. OK C++17 (GCC 7-32) TESTS 24 264 6041600
344787183 hzjhzjhzj C2 Oct. 20, 2025, 12:05 a.m. OK C++20 (GCC 13-64) TESTS 28 140 5017600
344745323 hzjhzjhzj C2 Oct. 19, 2025, 4:34 p.m. OK C++20 (GCC 13-64) TESTS 21 171 5017600
344756452 diobrando97 C2 Oct. 19, 2025, 6 p.m. OK C++20 (GCC 13-64) TESTS 24 171 7680000
344751589 stdfloat C2 Oct. 19, 2025, 5:37 p.m. OK C++20 (GCC 13-64) TESTS 21 171 14848000
344760533 Denislav_Manev C2 Oct. 19, 2025, 6:24 p.m. OK C++20 (GCC 13-64) TESTS 24 186 3276800
344806540 Ghulam_Junaid C2 Oct. 20, 2025, 5:11 a.m. OK C++20 (GCC 13-64) TESTS 29 187 819200
344783935 repmann C2 Oct. 19, 2025, 10:38 p.m. OK C++20 (GCC 13-64) TESTS 24 187 4812800
344788829 lijunze12 C2 Oct. 20, 2025, 12:44 a.m. OK C++20 (GCC 13-64) TESTS 28 202 6860800
344787668 JoelCH04 C2 Oct. 20, 2025, 12:17 a.m. OK C++20 (GCC 13-64) TESTS 28 202 10035200
344809437 abdelrhmanezzat C2 Oct. 20, 2025, 5:40 a.m. OK C++20 (GCC 13-64) TESTS 29 217 921600
344803544 123m456jx C2 Oct. 20, 2025, 4:35 a.m. OK C++23 (GCC 14-64, msys2) TESTS 29 140 102400
344789440 Lntano265 C2 Oct. 20, 2025, 12:58 a.m. OK C++23 (GCC 14-64, msys2) TESTS 29 140 204800
344779825 logonax C2 Oct. 19, 2025, 9:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 24 140 204800
344771440 jiangly C2 Oct. 19, 2025, 7:45 p.m. OK C++23 (GCC 14-64, msys2) TESTS 24 140 204800
344791020 piantouqu C2 Oct. 20, 2025, 1:29 a.m. OK C++23 (GCC 14-64, msys2) TESTS 29 140 6860800
344789420 Lntano265 C2 Oct. 20, 2025, 12:57 a.m. OK C++23 (GCC 14-64, msys2) TESTS 29 155 204800
344745530 gym123456 C2 Oct. 19, 2025, 4:34 p.m. OK C++23 (GCC 14-64, msys2) TESTS 21 156 18841600
344794303 yuyuan567 C2 Oct. 20, 2025, 2:26 a.m. OK C++23 (GCC 14-64, msys2) TESTS 29 171 11468800
344759070 OneIndexed C2 Oct. 19, 2025, 6:15 p.m. OK C++23 (GCC 14-64, msys2) TESTS 24 186 2048000
344791243 kanglr1013 C2 Oct. 20, 2025, 1:33 a.m. OK C++23 (GCC 14-64, msys2) TESTS 29 186 2457600
344794419 uffhottie C2 Oct. 20, 2025, 2:28 a.m. OK Go TESTS 29 1077 12697600
344754954 AAcup C2 Oct. 19, 2025, 5:53 p.m. OK Go TESTS 23 1499 22528000
344756211 nabina1395 C2 Oct. 19, 2025, 5:59 p.m. OK Java 21 TESTS 24 561 1024000
344778631 vineetiwari C2 Oct. 19, 2025, 9:06 p.m. OK Java 21 TESTS 24 577 10649600
344781998 cstemp C2 Oct. 19, 2025, 9:58 p.m. OK Java 21 TESTS 24 702 87961600
344753305 Balu2907 C2 Oct. 19, 2025, 5:44 p.m. OK Java 21 TESTS 21 1156 17612800
344759007 akshatjai258 C2 Oct. 19, 2025, 6:15 p.m. OK Java 21 TESTS 24 1171 151347200
344760657 akshatjai258 C2 Oct. 19, 2025, 6:25 p.m. OK Java 21 TESTS 24 1280 129228800
344811963 DJ1007 C2 Oct. 20, 2025, 6:04 a.m. OK Java 21 TESTS 29 2218 1536000
344805211 kevin_0911 C2 Oct. 20, 2025, 4:57 a.m. OK Java 8 TESTS 29 514 24985600
344812290 arnabpachal2004 C2 Oct. 20, 2025, 6:07 a.m. OK Java 8 TESTS 29 1858 16998400
344799753 xiaojuruo_haokee C2 Oct. 20, 2025, 3:43 a.m. OK Kotlin 2.2 TESTS 29 921 64204800
344783781 toryinside C2 Oct. 19, 2025, 10:34 p.m. OK PyPy 3 TESTS 24 1108 70041600
344787017 alexwice C2 Oct. 20, 2025, 12:01 a.m. OK PyPy 3-64 TESTS 27 374 42086400
344775989 gardengnome C2 Oct. 19, 2025, 8:33 p.m. OK PyPy 3-64 TESTS 24 452 33894400
344764672 once_and_again C2 Oct. 19, 2025, 6:50 p.m. OK PyPy 3-64 TESTS 24 468 39424000
344760024 ibraheemkureshi C2 Oct. 19, 2025, 6:21 p.m. OK PyPy 3-64 TESTS 24 484 35840000
344759221 monocrap C2 Oct. 19, 2025, 6:16 p.m. OK PyPy 3-64 TESTS 24 561 76902400
344745212 JosiSol C2 Oct. 19, 2025, 4:34 p.m. OK PyPy 3-64 TESTS 21 624 38092800
344809434 viditanupgupta C2 Oct. 20, 2025, 5:40 a.m. OK PyPy 3-64 TESTS 29 624 47616000
344765942 ardeelia C2 Oct. 19, 2025, 6:59 p.m. OK PyPy 3-64 TESTS 24 671 75878400
344750209 minuki646 C2 Oct. 19, 2025, 5:31 p.m. OK PyPy 3-64 TESTS 21 765 43008000
344776157 IcyGirl C2 Oct. 19, 2025, 8:35 p.m. OK PyPy 3-64 TESTS 24 780 84275200
344789513 jai_gurudev C2 Oct. 20, 2025, 12:59 a.m. OK Python 3 TESTS 29 1171 38195200
344799888 Spheniscine C2 Oct. 20, 2025, 3:44 a.m. OK Rust 2021 TESTS 29 140 307200
344779377 Maverick027 C2 Oct. 19, 2025, 9:17 p.m. OK Rust 2024 TESTS 24 109 10956800
344793122 null_lambda C2 Oct. 20, 2025, 2:08 a.m. OK Rust 2024 TESTS 29 202 18636800
344768037 pva701 C2 Oct. 19, 2025, 7:16 p.m. OK Rust 2024 TESTS 24 202 28364800

remove filters

Back to search problems