Codeforces Round 1123 (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
2267 Codeforces Round 1123 (Div. 2) FINISHED False 8100 833066 Sept. 25, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 9784 ) C GCD Treasury PROGRAMMING greedy math number theory

The greedy pirate Dimash found a treasury. It consists of (n) piles of coins, numbered from (1) to (n). The (i)-th pile contains exactly (a_i) coins. Pirate Dimash has a number (x) that he can use to steal coins from the treasury. The stealing process works as follows: First, he chooses an index (1\le i\le n) such that (a_i\gt 0) and (\gcd)(^{\text{∗}})((a_i, x) \neq 1). If there is no such index, the pirate stops. Now let (\gcd(a_i, x)) be (g). The pirate steals exactly (g) coins from pile (i), after which (a_i) decreases by (g). Finally, he sets (x) to (g) and continues stealing coins. Your task is to help the pirate steal the maximum possible number of coins. Find the maximum number of coins that can be stolen from the treasury. (^{\text{∗}})(\gcd(a_i, x)) denotes the greatest common divisor (GCD) of integers (a_i) and (x). 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 test case contains two integers (n) and (x) ((1\le n, x\le 3\cdot 10^5)) — the number of piles of coins in the treasury and the pirate's number. The second line of each test case contains (n) integers (a_1, a_2, \ldots a_n) ((1 \le a_i \le 3\cdot 10^5)). It is guaranteed that the sum of (n) over all test cases does not exceed (3\cdot 10^5). For each test case, output one number — the maximum number of coins that can be stolen. In the first test case, no coin can be stolen. In the second test case, the pirate steals as follows. The pirate chooses pile number (3). He takes (4) coins, after which the treasury becomes (2, 3, 0) and (x) becomes (4). The pirate chooses pile number (1). He takes (2) coins, after which the treasury becomes (0, 3, 0), and (x) becomes (2). No suitable indices

Tutorials

157126

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
392116122 Bitwise_Mind C Sept. 26, 2026, 5:59 a.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392104363 deividsleepy C Sept. 26, 2026, 3:19 a.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392099411 Fours C Sept. 26, 2026, 1:15 a.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392098645 Goolu C Sept. 26, 2026, 1 a.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392090351 SeedRd C Sept. 25, 2026, 8:57 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392087596 ashmelev C Sept. 25, 2026, 8:04 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392083403 Singularity023 C Sept. 25, 2026, 7:01 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392066032 strain7626 C Sept. 25, 2026, 4:36 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392065739 aditya-codee C Sept. 25, 2026, 4:36 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392064937 Rana26302022 C Sept. 25, 2026, 4:33 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
392102804 shrav07 C Sept. 26, 2026, 2:40 a.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392094540 Blazagon C Sept. 25, 2026, 11:01 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392088520 mabolo C Sept. 25, 2026, 8:22 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392086540 nikzzs C Sept. 25, 2026, 7:47 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392085047 adarshpatel8054 C Sept. 25, 2026, 7:23 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392069042 mahendra_l07 C Sept. 25, 2026, 4:45 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392067234 annoying7999 C Sept. 25, 2026, 4:40 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392067156 amretyll C Sept. 25, 2026, 4:40 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392067135 bsjsaikou10 C Sept. 25, 2026, 4:40 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392061472 Taimoor_ C Sept. 25, 2026, 4:23 p.m. OK C++20 (GCC 13-64) TESTS 20 78 0
392093681 hodza C Sept. 25, 2026, 10:30 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 31 2150400
392115951 XploitGhost C Sept. 26, 2026, 5:58 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392109512 duelist_1883 C Sept. 26, 2026, 4:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392103541 ankitraj803120 C Sept. 26, 2026, 2:59 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392103033 kavish2007 C Sept. 26, 2026, 2:45 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392100530 Sh4d0wC4t C Sept. 26, 2026, 1:40 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392092133 Oikawaa C Sept. 25, 2026, 9:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392091575 JOO. C Sept. 25, 2026, 9:22 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392090975 ShiningShadow14 C Sept. 25, 2026, 9:09 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392087900 vishal340 C Sept. 25, 2026, 8:10 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
392070543 kavyakaushal007 C Sept. 25, 2026, 4:49 p.m. OK GNU C11 TESTS 20 109 1331200
392106699 silicalet C Sept. 26, 2026, 4:08 a.m. OK Haskell TESTS 20 1078 15872000
392058610 Satyam_Arg C Sept. 25, 2026, 4:15 p.m. OK Java 21 TESTS 20 218 307200
392063750 Raj_coder C Sept. 25, 2026, 4:30 p.m. OK Java 21 TESTS 20 234 307200
392082383 bethebest100times C Sept. 25, 2026, 6:47 p.m. OK Java 21 TESTS 20 250 716800
392109791 NpHardcore_05 C Sept. 26, 2026, 4:58 a.m. OK Java 21 TESTS 20 265 819200
392062926 Byte_Master2028 C Sept. 25, 2026, 4:27 p.m. OK Java 21 TESTS 20 265 1945600
392063382 electrophile093 C Sept. 25, 2026, 4:29 p.m. OK Java 21 TESTS 20 281 716800
392066313 liomsv C Sept. 25, 2026, 4:37 p.m. OK Java 21 TESTS 20 296 512000
392072127 arthkj0911 C Sept. 25, 2026, 5:07 p.m. OK Java 21 TESTS 20 296 921600
392063957 rahulx1515 C Sept. 25, 2026, 4:30 p.m. OK Java 21 TESTS 20 296 1228800
392107699 saiyelmatwad13 C Sept. 26, 2026, 4:25 a.m. OK Java 21 TESTS 20 296 4403200
392059594 harsh.sharma.gs25 C Sept. 25, 2026, 4:18 p.m. OK Java 8 TESTS 20 156 0
392069577 yuvakumaran_r C Sept. 25, 2026, 4:47 p.m. OK Java 8 TESTS 20 234 0
392105956 NightSage C Sept. 26, 2026, 3:53 a.m. OK Java 8 TESTS 20 531 0
392060401 KamilIskhakov C Sept. 25, 2026, 4:20 p.m. OK Java 8 TESTS 20 562 0
392064320 nabeelafatima256 C Sept. 25, 2026, 4:31 p.m. OK Java 8 TESTS 20 578 0
392059672 viratsanju018 C Sept. 25, 2026, 4:18 p.m. OK Java 8 TESTS 20 593 0
392060715 Harsha_Gajjala C Sept. 25, 2026, 4:21 p.m. OK Java 8 TESTS 20 687 0
392074486 AllNamesTaken C Sept. 25, 2026, 5:24 p.m. OK Java 8 TESTS 20 718 512000
392059698 asbro3886 C Sept. 25, 2026, 4:18 p.m. OK Java 8 TESTS 20 968 0
392070330 dineshI C Sept. 25, 2026, 4:49 p.m. OK Java 8 TESTS 20 984 0
392061294 Sergey.Bankevich C Sept. 25, 2026, 4:23 p.m. OK Kotlin 1.7 TESTS 20 671 21094400
392070297 mironbrinkovskiy C Sept. 25, 2026, 4:48 p.m. OK Node.js TESTS 20 203 60928000
392100288 mo-hit C Sept. 26, 2026, 1:33 a.m. OK PyPy 3 TESTS 20 328 28262400
392066705 EarthGo C Sept. 25, 2026, 4:38 p.m. OK PyPy 3 TESTS 20 437 20582400
392060888 DOOMDOOMDOOM C Sept. 25, 2026, 4:21 p.m. OK PyPy 3 TESTS 20 437 22528000
392062313 augmentedblue C Sept. 25, 2026, 4:26 p.m. OK PyPy 3 TESTS 20 625 20480000
392059170 Himari1618 C Sept. 25, 2026, 4:17 p.m. OK PyPy 3 TESTS 20 625 23142400
392062959 Aarav_kh C Sept. 25, 2026, 4:27 p.m. OK PyPy 3 TESTS 20 656 22118400
392063286 Lososb C Sept. 25, 2026, 4:28 p.m. OK PyPy 3 TESTS 20 1000 22528000
392105354 lu2m1n C Sept. 26, 2026, 3:40 a.m. OK PyPy 3-64 TESTS 20 156 34304000
392061035 Suliaoaoaoaoa C Sept. 25, 2026, 4:22 p.m. OK PyPy 3-64 TESTS 20 156 35123200
392112765 atharv_bind C Sept. 26, 2026, 5:31 a.m. OK PyPy 3-64 TESTS 20 156 39424000
392069479 dulat_akbulatov C Sept. 25, 2026, 4:46 p.m. OK PyPy 3-64 TESTS 20 171 25190400
392061816 Alpha_Orionis C Sept. 25, 2026, 4:24 p.m. OK PyPy 3-64 TESTS 20 171 34201600
392063337 Asterix22 C Sept. 25, 2026, 4:29 p.m. OK PyPy 3-64 TESTS 20 171 39936000
392066186 pradhyumna_k_m C Sept. 25, 2026, 4:37 p.m. OK PyPy 3-64 TESTS 20 187 18739200
392102390 xing_meng C Sept. 26, 2026, 2:30 a.m. OK PyPy 3-64 TESTS 20 187 34099200
392089828 stormboy C Sept. 25, 2026, 8:46 p.m. OK PyPy 3-64 TESTS 20 187 35942400
392067582 chakrabanda C Sept. 25, 2026, 4:41 p.m. OK PyPy 3-64 TESTS 20 187 38809600
392072995 vpiyush171 C Sept. 25, 2026, 5:13 p.m. OK Python 3 TESTS 20 234 34508800
392059399 MOHAMED_AHR C Sept. 25, 2026, 4:17 p.m. OK Python 3 TESTS 20 234 34713600
392060513 sh20raj C Sept. 25, 2026, 4:21 p.m. OK Python 3 TESTS 20 265 34201600
392068459 avidipsarkar C Sept. 25, 2026, 4:44 p.m. OK Python 3 TESTS 20 265 34611200
392068908 Synthexia C Sept. 25, 2026, 4:45 p.m. OK Python 3 TESTS 20 281 35225600
392062882 cy171 C Sept. 25, 2026, 4:27 p.m. OK Python 3 TESTS 20 296 34816000
392070586 Levi47 C Sept. 25, 2026, 4:49 p.m. OK Python 3 TESTS 20 296 35430400
392062491 classisover2 C Sept. 25, 2026, 4:26 p.m. OK Python 3 TESTS 20 359 34099200
392057732 nazerawig C Sept. 25, 2026, 4:13 p.m. OK Python 3 TESTS 20 359 34816000
392070483 freke_44 C Sept. 25, 2026, 4:49 p.m. OK Python 3 TESTS 20 375 38195200
392073224 NNChen C Sept. 25, 2026, 5:14 p.m. OK Rust 2024 TESTS 20 109 3481600
392085488 viveksahani39266 C Sept. 25, 2026, 7:30 p.m. OK Rust 2024 TESTS 20 1515 3686400

remove filters

Back to search problems