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
B"You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i . Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex x to vertex y (including these two vertices). For every integer from 1 to 2 cdot 10^5 you have to count the number of pairs (x, y) (1 <= x <= y <= n) such that g(x, y) is equal to this number. The first line contains one integer n -- the number of vertices (1 <= n <= 2 cdot 10^5) . The second line contains n integers a_1 , a_2 , ..., a_n (1 <= a_i <= 2 cdot 10^5) -- the numbers written on vertices. Then n - 1 lines follow, each containing two integers x and y (1 <= x, y <= n, x ne y) denoting an edge connecting vertex x with vertex y . It is guaranteed that these edges form a tree. For every integer i from 1 to 2 cdot 10^5 do the following: if there is no pair (x, y) such that x <= y and g(x, y) = i , don't output anything. Otherwise output two integers: i and the number of aforementioned pairs. You have to consider the values of i in ascending order. See the examples for better understanding. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
40521866 |
froggyWCH |
G |
July 18, 2018, 5 p.m. |
OK |
GNU C++ |
TESTS |
111 |
982 |
24268800 |
|
2400 |
41153725 |
luogu_bot4 |
G |
Aug. 3, 2018, 10:39 a.m. |
OK |
GNU C++ |
TESTS |
111 |
997 |
18534400 |
|
2400 |
41153325 |
luogu_bot3 |
G |
Aug. 3, 2018, 10:21 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1029 |
15257600 |
|
2400 |
39239132 |
vjudge4 |
G |
June 14, 2018, 9:58 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1029 |
15257600 |
|
2400 |
39239095 |
vjudge1 |
G |
June 14, 2018, 9:57 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1029 |
15257600 |
|
2400 |
40507170 |
vjudge4 |
G |
July 18, 2018, 9:02 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1029 |
17817600 |
|
2400 |
40600830 |
vjudge3 |
G |
July 21, 2018, 8:29 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1060 |
17817600 |
|
2400 |
40600738 |
vjudge3 |
G |
July 21, 2018, 8:26 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1060 |
17817600 |
|
2400 |
40474855 |
vjudge1 |
G |
July 17, 2018, 11:22 a.m. |
OK |
GNU C++ |
TESTS |
111 |
1076 |
18636800 |
|
2400 |
39823034 |
luogu_bot3 |
G |
July 1, 2018, 1:56 p.m. |
OK |
GNU C++ |
TESTS |
111 |
1091 |
20684800 |
|
2400 |
55307474 |
rainboy |
G |
June 8, 2019, 3:25 p.m. |
OK |
GNU C11 |
TESTS |
111 |
982 |
7987200 |
|
2400 |
40977236 |
ReaLNero1 |
G |
July 30, 2018, 4:06 p.m. |
OK |
GNU C++11 |
TESTS |
111 |
685 |
171724800 |
|
2400 |
39145430 |
min1013 |
G |
June 11, 2018, 11:57 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
701 |
20070400 |
|
2400 |
39116127 |
nhho |
G |
June 10, 2018, 11:57 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
701 |
171622400 |
|
2400 |
39178625 |
hhhjhy |
G |
June 12, 2018, 2:41 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
764 |
14643200 |
|
2400 |
39215583 |
mxzf0213 |
G |
June 13, 2018, 12:02 p.m. |
OK |
GNU C++11 |
TESTS |
111 |
810 |
15155200 |
|
2400 |
69454772 |
zyn_615 |
G |
Jan. 24, 2020, 8:04 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
873 |
13721600 |
|
2400 |
69454838 |
zyn_615 |
G |
Jan. 24, 2020, 8:06 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
873 |
13721600 |
|
2400 |
49034326 |
TristeanimaCZY |
G |
Jan. 27, 2019, 1:55 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
889 |
23449600 |
|
2400 |
69509761 |
liuweih |
G |
Jan. 25, 2020, 10:04 a.m. |
OK |
GNU C++11 |
TESTS |
111 |
920 |
24268800 |
|
2400 |
39967118 |
krijgertje |
G |
July 4, 2018, 9:12 p.m. |
OK |
GNU C++11 |
TESTS |
111 |
920 |
26624000 |
|
2400 |
39222232 |
ekzhang |
G |
June 13, 2018, 4:51 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
701 |
171827200 |
|
2400 |
39222334 |
ekzhang |
G |
June 13, 2018, 4:55 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
764 |
172441600 |
|
2400 |
42765557 |
alokpatra1998 |
G |
Sept. 11, 2018, 1:02 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
841 |
37068800 |
|
2400 |
39194972 |
Heisenbug |
G |
June 12, 2018, 2:56 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
857 |
37068800 |
|
2400 |
39122403 |
noDreams |
G |
June 10, 2018, 1:34 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
873 |
258867200 |
|
2400 |
39193026 |
dafeng |
G |
June 12, 2018, 1:40 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
904 |
255488000 |
|
2400 |
39178641 |
vjudge3 |
G |
June 12, 2018, 2:42 a.m. |
OK |
GNU C++14 |
TESTS |
111 |
920 |
14745600 |
|
2400 |
49034265 |
gubeiqg |
G |
Jan. 27, 2019, 1:52 a.m. |
OK |
GNU C++14 |
TESTS |
111 |
935 |
23654400 |
|
2400 |
39124127 |
I_love_chickpea |
G |
June 10, 2018, 2:37 p.m. |
OK |
GNU C++14 |
TESTS |
111 |
967 |
25292800 |
|
2400 |
40474681 |
Eden_CY |
G |
July 17, 2018, 11:18 a.m. |
OK |
GNU C++14 |
TESTS |
111 |
1123 |
18739200 |
|
2400 |
68677341 |
SGHD |
G |
Jan. 12, 2020, 7:19 p.m. |
OK |
GNU C++17 |
TESTS |
111 |
732 |
48128000 |
|
2400 |
39108751 |
ghostfly233 |
G |
June 10, 2018, 11:21 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
779 |
20377600 |
|
2400 |
54375924 |
betrue12 |
G |
May 19, 2019, 8:47 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
779 |
112742400 |
|
2400 |
50877242 |
oToToT |
G |
March 6, 2019, 7:02 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
795 |
175718400 |
|
2400 |
39115956 |
NK-Sparrow |
G |
June 10, 2018, 11:56 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
810 |
20992000 |
|
2400 |
68677192 |
SGHD |
G |
Jan. 12, 2020, 7:14 p.m. |
OK |
GNU C++17 |
TESTS |
111 |
826 |
62156800 |
|
2400 |
50877426 |
oToToT |
G |
March 6, 2019, 7:09 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
951 |
175718400 |
|
2400 |
39182814 |
liujianbo |
G |
June 12, 2018, 6:56 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
982 |
14745600 |
|
2400 |
63296647 |
vjudge1 |
G |
Oct. 24, 2019, 1:08 p.m. |
OK |
GNU C++17 |
TESTS |
111 |
982 |
17920000 |
|
2400 |
39136762 |
q234rty |
G |
June 11, 2018, 5:01 a.m. |
OK |
GNU C++17 |
TESTS |
111 |
1091 |
30720000 |
|
2400 |
64553479 |
mmaxio |
G |
Nov. 9, 2019, 1:48 a.m. |
OK |
Java 11 |
TESTS |
111 |
4321 |
41881600 |
|
2400 |
42816618 |
tri |
G |
Sept. 13, 2018, 2:17 a.m. |
OK |
Java 8 |
TESTS |
111 |
904 |
19660800 |
|
2400 |
58397020 |
fetetriste |
G |
Aug. 6, 2019, 4:03 p.m. |
OK |
Java 8 |
TESTS |
111 |
1606 |
39936000 |
|
2400 |
55307522 |
Dukkha |
G |
June 8, 2019, 3:26 p.m. |
OK |
Java 8 |
TESTS |
111 |
1684 |
18124800 |
|
2400 |
48268285 |
wadissimo |
G |
Jan. 11, 2019, 10:20 p.m. |
OK |
Java 8 |
TESTS |
111 |
2043 |
268390400 |
|
2400 |
64557077 |
aminul |
G |
Nov. 9, 2019, 4:22 a.m. |
OK |
Java 8 |
TESTS |
111 |
2354 |
32563200 |
|
2400 |
39147460 |
uwi |
G |
June 11, 2018, 1:15 p.m. |
OK |
Java 8 |
TESTS |
111 |
2527 |
27852800 |
|
2400 |
53173878 |
Ahmed_Diab |
G |
April 23, 2019, 1:35 a.m. |
OK |
Java 8 |
TESTS |
111 |
3072 |
26624000 |
|
2400 |
57605566 |
StayAwayFromBitches |
G |
July 23, 2019, 5:44 p.m. |
OK |
Java 8 |
TESTS |
111 |
3198 |
36556800 |
|
2400 |
57605448 |
StayAwayFromBitches |
G |
July 23, 2019, 5:41 p.m. |
OK |
Java 8 |
TESTS |
111 |
3587 |
36659200 |
|
2400 |
41025063 |
vovacomua |
G |
July 31, 2018, 2:27 p.m. |
OK |
Java 8 |
TESTS |
111 |
3665 |
33894400 |
|
2400 |
39456255 |
lxn |
G |
June 21, 2018, 8:51 a.m. |
OK |
MS C++ |
TESTS |
111 |
701 |
18432000 |
|
2400 |
39457445 |
lxn |
G |
June 21, 2018, 9:40 a.m. |
OK |
MS C++ |
TESTS |
111 |
904 |
20070400 |
|
2400 |
remove filters
Back to search problems