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.
Problems
This is the hard version of the problem. The only difference is that (1 \le x \le 5 \cdot 10^5) . On the way home after buying his favorite soda "Zola Cero", Egor saw that elections for the position of "Best Number" are taking place in Saransk. There are (n) people at the polling station. Each person brought a number (a_i). When the (i)-th person enters the voting booth, they choose a candidate that is a divisor of the number (a_i). Let the chosen candidate be (p_i). After everyone has voted, we get an array of votes (p_1, p_2, \ldots, p_n). Egor really likes the number (x) and considers the voting ideal if (x \cdot {lcm}(p_1, p_2, \ldots, p_n))(^{\text{∗}}) = (p_1 \cdot p_2 \cdot \ldots \cdot p_n). Help him find the number of different(^{\text{†}}) arrays (p) modulo (10^9 + 7) that are ideal. (^{\text{∗}})(lcm) — least common multiple . (^{\text{†}})Two arrays of votes are considered different if there exists an index (i) where the two arrays have different elements. The first line contains a single integer (t) ((1 \leq t \leq 10^4)) — the number of test cases. Then (t) test cases follow. The first line of each test case contains two integers (n) and (x) ((1 \leq n \leq 10^5), (1 \leq x \leq 5 \cdot 10^5)) — the number of voters at the polling station and Egor's favorite number. The second line of each test case contains (n) integers: (a_1, a_2, \dots, a_n) ((1 \leq a_i \leq 5 \cdot 10^5)) — the numbers brought by the voters. It is guaranteed that the sum of (n) over all test cases does not exceed (10^5). For each test case, output the number of ways modulo (10^9 + 7) to vote so that the resulting array of votes satisfies the condition. |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
378457165 |
ana.pacheco.loayzza |
F2 |
June 12, 2026, 10:50 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
203 |
9420800 |
|
|
|
378455147 |
SiddharthJoshi |
F2 |
June 12, 2026, 9:36 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
359 |
35430400 |
|
|
|
378553283 |
yashday |
F2 |
June 13, 2026, 7:40 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
515 |
14438400 |
|
|
|
378451456 |
testdonna2 |
F2 |
June 12, 2026, 8:07 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
531 |
6041600 |
|
|
|
378464737 |
brrbrrpatapim_ |
F2 |
June 13, 2026, 3:16 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
890 |
2048000 |
|
|
|
378553413 |
Basil815 |
F2 |
June 13, 2026, 7:42 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
906 |
14643200 |
|
|
|
378529313 |
Wolver1ne |
F2 |
June 13, 2026, 3:21 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
1000 |
11468800 |
|
|
|
378532134 |
Wolver1ne |
F2 |
June 13, 2026, 3:48 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
1046 |
12185600 |
|
|
|
378532037 |
Wolver1ne |
F2 |
June 13, 2026, 3:47 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
1046 |
13209600 |
|
|
|
378556249 |
1_man_ARMY |
F2 |
June 13, 2026, 8:37 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
76 |
1046 |
17510400 |
|
|
|
378499903 |
UncleEvy |
F2 |
June 13, 2026, 10:31 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
203 |
20582400 |
|
|
|
378462771 |
bitmask1999 |
F2 |
June 13, 2026, 2:29 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
437 |
12083200 |
|
|
|
378504999 |
UncleEvy |
F2 |
June 13, 2026, 11:20 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
500 |
19046400 |
|
|
|
378452239 |
usedchang |
F2 |
June 12, 2026, 8:23 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
546 |
1740800 |
|
|
|
378555752 |
retr0foxx_osu |
F2 |
June 13, 2026, 8:27 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
656 |
25907200 |
|
|
|
378504906 |
rzgbl |
F2 |
June 13, 2026, 11:19 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
921 |
47820800 |
|
|
|
378456678 |
Spoyy2 |
F2 |
June 12, 2026, 10:29 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
1000 |
7168000 |
|
|
|
378470097 |
Liqy |
F2 |
June 13, 2026, 4:53 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
1187 |
9830400 |
|
|
|
378564982 |
Liqy |
F2 |
June 14, 2026, 2:24 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
1187 |
48128000 |
|
|
|
378550383 |
Lapoux |
F2 |
June 13, 2026, 6:54 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
76 |
1187 |
48128000 |
|
|
|
378455174 |
SiddharthJoshi |
F2 |
June 12, 2026, 9:37 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
125 |
43110400 |
|
|
|
378527664 |
Semyazi |
F2 |
June 13, 2026, 3:04 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
156 |
9728000 |
|
|
|
378465806 |
Marckess |
F2 |
June 13, 2026, 3:38 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
171 |
19558400 |
|
|
|
378460547 |
aryanc403 |
F2 |
June 13, 2026, 1:20 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
171 |
40550400 |
|
|
|
378460789 |
aryanc403 |
F2 |
June 13, 2026, 1:28 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
187 |
36147200 |
|
|
|
378460750 |
aryanc403 |
F2 |
June 13, 2026, 1:26 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
218 |
40550400 |
|
|
|
378551137 |
jhemn001 |
F2 |
June 13, 2026, 7:06 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
234 |
16588800 |
|
|
|
378543335 |
work.mishrasaksham |
F2 |
June 13, 2026, 5:39 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
250 |
3788800 |
|
|
|
378460374 |
aryanc403 |
F2 |
June 13, 2026, 1:14 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
250 |
33587200 |
|
|
|
378545312 |
4M49_H3R3 |
F2 |
June 13, 2026, 5:59 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
76 |
296 |
26112000 |
|
|
|
378450078 |
hg_2005 |
F2 |
June 12, 2026, 7:42 p.m. |
OK |
Java 21 |
TESTS |
76 |
1468 |
232960000 |
|
|
|
378562017 |
dzhi |
F2 |
June 14, 2026, 12:34 a.m. |
OK |
Java 21 |
TESTS |
76 |
2203 |
6246400 |
|
|
|
378561997 |
dzhi |
F2 |
June 14, 2026, 12:33 a.m. |
OK |
Java 21 |
TESTS |
76 |
2843 |
4710400 |
|
|
|
378561925 |
dzhi |
F2 |
June 14, 2026, 12:29 a.m. |
OK |
Java 21 |
TESTS |
76 |
2937 |
5324800 |
|
|
|
378470483 |
golomb |
F2 |
June 13, 2026, 4:59 a.m. |
OK |
PyPy 3-64 |
TESTS |
76 |
1031 |
21708800 |
|
|
|
378546101 |
Mula_Wang |
F2 |
June 13, 2026, 6:07 p.m. |
OK |
PyPy 3-64 |
TESTS |
76 |
2281 |
20172800 |
|
|
|
378455858 |
Hyder1102 |
F2 |
June 12, 2026, 10:01 p.m. |
OK |
PyPy 3-64 |
TESTS |
76 |
2453 |
19046400 |
|
|
|
378455639 |
Hyder1102 |
F2 |
June 12, 2026, 9:53 p.m. |
OK |
PyPy 3-64 |
TESTS |
76 |
2531 |
27033600 |
|
|
|
378455447 |
Hyder1102 |
F2 |
June 12, 2026, 9:46 p.m. |
OK |
PyPy 3-64 |
TESTS |
76 |
2687 |
59801600 |
|
|
|
378452852 |
Hyder1102 |
F2 |
June 12, 2026, 8:37 p.m. |
OK |
PyPy 3-64 |
TESTS |
76 |
2765 |
40960000 |
|
|
remove filters
Back to search problems