#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 * 4 + 222 + 2;
vector<int> g[N];
void top (int v, vector<bool>&used, vector<int>&ans) {
used[v] = 1;
for (auto to : g[v]) {
if (!used[to]) {
top (to, used, ans);
}
}
ans.push_back(v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int Q;
cin >> Q;
int n = Q;
vector<int> a (n + 1), b (n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
int l = a[i] + b[i] - __gcd (a[i], b[i]) - 1;
swap (a[i], b[i]);
for (int j = 0; j <= l; ++j) {
if (j - a[i] >= 0) {
g[j - a[i]].push_back (j);
}
if (j - b[i] >= 0) {
g[j].push_back (j - b[i]);
}
}
vector<int> ans;
vector<bool> used (l + 1, false);
for (int j = 0; j <= l; ++j) {
if (!used[j]) {
top (j, used, ans);
}
}
for (int j = 0; j <= l; ++j) g[j].clear();
reverse (begin (ans), end (ans));
vector<int> d (l + 1);
for (int j = 0; j <= l; ++j) {
d[ans[j]] = j;
}
cout << l << '\n';
for (int j = 1; j <= l; ++j) {
cout << d[j] - d[j - 1] << ' ';
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Ok |
2 |
Correct |
4 ms |
9868 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9820 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
5 ms |
9820 KB |
Ok |
9 |
Correct |
5 ms |
9860 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
7 ms |
9820 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Ok |
2 |
Correct |
5 ms |
10076 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
5 ms |
9704 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
5 ms |
9820 KB |
Ok |
7 |
Correct |
10 ms |
10844 KB |
Ok |
8 |
Correct |
7 ms |
10332 KB |
Ok |
9 |
Correct |
10 ms |
10980 KB |
Ok |
10 |
Correct |
8 ms |
10332 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Ok |
2 |
Correct |
4 ms |
9820 KB |
Ok |
3 |
Correct |
3 ms |
9856 KB |
Ok |
4 |
Correct |
4 ms |
9820 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
5 ms |
10076 KB |
Ok |
8 |
Correct |
4 ms |
9816 KB |
Ok |
9 |
Correct |
4 ms |
9820 KB |
Ok |
10 |
Correct |
5 ms |
9824 KB |
Ok |
11 |
Correct |
4 ms |
9820 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Ok |
2 |
Correct |
4 ms |
9816 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9820 KB |
Ok |
5 |
Correct |
4 ms |
9824 KB |
Ok |
6 |
Correct |
72 ms |
28896 KB |
Ok |
7 |
Correct |
57 ms |
28232 KB |
Ok |
8 |
Correct |
103 ms |
32284 KB |
Ok |
9 |
Correct |
81 ms |
27644 KB |
Ok |
10 |
Correct |
53 ms |
22876 KB |
Ok |
11 |
Correct |
90 ms |
34824 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Ok |
2 |
Correct |
4 ms |
9868 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9820 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
5 ms |
9820 KB |
Ok |
9 |
Correct |
5 ms |
9860 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
7 ms |
9820 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
13 |
Correct |
4 ms |
9816 KB |
Ok |
14 |
Correct |
4 ms |
9820 KB |
Ok |
15 |
Correct |
3 ms |
9856 KB |
Ok |
16 |
Correct |
4 ms |
9820 KB |
Ok |
17 |
Correct |
4 ms |
9820 KB |
Ok |
18 |
Correct |
4 ms |
9820 KB |
Ok |
19 |
Correct |
5 ms |
10076 KB |
Ok |
20 |
Correct |
4 ms |
9816 KB |
Ok |
21 |
Correct |
4 ms |
9820 KB |
Ok |
22 |
Correct |
5 ms |
9824 KB |
Ok |
23 |
Correct |
4 ms |
9820 KB |
Ok |
24 |
Correct |
5 ms |
9816 KB |
Ok |
25 |
Correct |
5 ms |
10072 KB |
Ok |
26 |
Correct |
5 ms |
9820 KB |
Ok |
27 |
Correct |
5 ms |
10000 KB |
Ok |
28 |
Correct |
5 ms |
9896 KB |
Ok |
29 |
Correct |
4 ms |
9820 KB |
Ok |
30 |
Correct |
4 ms |
9820 KB |
Ok |
31 |
Correct |
8 ms |
9940 KB |
Ok |
32 |
Correct |
5 ms |
9820 KB |
Ok |
33 |
Correct |
5 ms |
9820 KB |
Ok |
34 |
Correct |
6 ms |
10076 KB |
Ok |
35 |
Correct |
6 ms |
10332 KB |
Ok |
36 |
Correct |
6 ms |
10332 KB |
Ok |
37 |
Correct |
6 ms |
10332 KB |
Ok |
38 |
Correct |
6 ms |
10368 KB |
Ok |
39 |
Correct |
6 ms |
10072 KB |
Ok |
40 |
Correct |
9 ms |
10584 KB |
Ok |
41 |
Correct |
7 ms |
10328 KB |
Ok |
42 |
Correct |
6 ms |
10332 KB |
Ok |
43 |
Correct |
7 ms |
10332 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Ok |
2 |
Correct |
4 ms |
9868 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9820 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
5 ms |
9820 KB |
Ok |
9 |
Correct |
5 ms |
9860 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
7 ms |
9820 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
13 |
Correct |
4 ms |
9820 KB |
Ok |
14 |
Correct |
5 ms |
10076 KB |
Ok |
15 |
Correct |
4 ms |
9820 KB |
Ok |
16 |
Correct |
5 ms |
9704 KB |
Ok |
17 |
Correct |
4 ms |
9820 KB |
Ok |
18 |
Correct |
5 ms |
9820 KB |
Ok |
19 |
Correct |
10 ms |
10844 KB |
Ok |
20 |
Correct |
7 ms |
10332 KB |
Ok |
21 |
Correct |
10 ms |
10980 KB |
Ok |
22 |
Correct |
8 ms |
10332 KB |
Ok |
23 |
Correct |
4 ms |
9816 KB |
Ok |
24 |
Correct |
4 ms |
9820 KB |
Ok |
25 |
Correct |
3 ms |
9856 KB |
Ok |
26 |
Correct |
4 ms |
9820 KB |
Ok |
27 |
Correct |
4 ms |
9820 KB |
Ok |
28 |
Correct |
4 ms |
9820 KB |
Ok |
29 |
Correct |
5 ms |
10076 KB |
Ok |
30 |
Correct |
4 ms |
9816 KB |
Ok |
31 |
Correct |
4 ms |
9820 KB |
Ok |
32 |
Correct |
5 ms |
9824 KB |
Ok |
33 |
Correct |
4 ms |
9820 KB |
Ok |
34 |
Correct |
5 ms |
9816 KB |
Ok |
35 |
Correct |
5 ms |
10072 KB |
Ok |
36 |
Correct |
5 ms |
9820 KB |
Ok |
37 |
Correct |
5 ms |
10000 KB |
Ok |
38 |
Correct |
5 ms |
9896 KB |
Ok |
39 |
Correct |
4 ms |
9820 KB |
Ok |
40 |
Correct |
4 ms |
9820 KB |
Ok |
41 |
Correct |
8 ms |
9940 KB |
Ok |
42 |
Correct |
5 ms |
9820 KB |
Ok |
43 |
Correct |
5 ms |
9820 KB |
Ok |
44 |
Correct |
6 ms |
10076 KB |
Ok |
45 |
Correct |
6 ms |
10332 KB |
Ok |
46 |
Correct |
6 ms |
10332 KB |
Ok |
47 |
Correct |
6 ms |
10332 KB |
Ok |
48 |
Correct |
6 ms |
10368 KB |
Ok |
49 |
Correct |
6 ms |
10072 KB |
Ok |
50 |
Correct |
9 ms |
10584 KB |
Ok |
51 |
Correct |
7 ms |
10328 KB |
Ok |
52 |
Correct |
6 ms |
10332 KB |
Ok |
53 |
Correct |
7 ms |
10332 KB |
Ok |
54 |
Correct |
48 ms |
15640 KB |
Ok |
55 |
Correct |
55 ms |
16164 KB |
Ok |
56 |
Correct |
52 ms |
15972 KB |
Ok |
57 |
Correct |
41 ms |
14736 KB |
Ok |
58 |
Correct |
49 ms |
15828 KB |
Ok |
59 |
Correct |
48 ms |
15336 KB |
Ok |
60 |
Correct |
44 ms |
14964 KB |
Ok |
61 |
Correct |
42 ms |
15304 KB |
Ok |
62 |
Correct |
58 ms |
16288 KB |
Ok |
63 |
Correct |
45 ms |
15068 KB |
Ok |
64 |
Correct |
55 ms |
15920 KB |
Ok |
65 |
Correct |
51 ms |
15852 KB |
Ok |
66 |
Correct |
47 ms |
15508 KB |
Ok |
67 |
Correct |
49 ms |
15252 KB |
Ok |
68 |
Correct |
50 ms |
15660 KB |
Ok |
69 |
Correct |
119 ms |
25924 KB |
Ok |
70 |
Correct |
114 ms |
25664 KB |
Ok |
71 |
Correct |
108 ms |
22936 KB |
Ok |
72 |
Correct |
101 ms |
25956 KB |
Ok |
73 |
Correct |
112 ms |
23336 KB |
Ok |
74 |
Correct |
117 ms |
24676 KB |
Ok |
75 |
Correct |
107 ms |
25448 KB |
Ok |
76 |
Correct |
116 ms |
25916 KB |
Ok |
77 |
Correct |
103 ms |
24268 KB |
Ok |
78 |
Correct |
112 ms |
25884 KB |
Ok |
79 |
Correct |
112 ms |
24616 KB |
Ok |
80 |
Correct |
99 ms |
23356 KB |
Ok |
81 |
Correct |
114 ms |
25660 KB |
Ok |
82 |
Correct |
108 ms |
24652 KB |
Ok |
83 |
Correct |
105 ms |
25908 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Ok |
2 |
Correct |
4 ms |
9868 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9820 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
5 ms |
9820 KB |
Ok |
9 |
Correct |
5 ms |
9860 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
7 ms |
9820 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
13 |
Correct |
4 ms |
9820 KB |
Ok |
14 |
Correct |
5 ms |
10076 KB |
Ok |
15 |
Correct |
4 ms |
9820 KB |
Ok |
16 |
Correct |
5 ms |
9704 KB |
Ok |
17 |
Correct |
4 ms |
9820 KB |
Ok |
18 |
Correct |
5 ms |
9820 KB |
Ok |
19 |
Correct |
10 ms |
10844 KB |
Ok |
20 |
Correct |
7 ms |
10332 KB |
Ok |
21 |
Correct |
10 ms |
10980 KB |
Ok |
22 |
Correct |
8 ms |
10332 KB |
Ok |
23 |
Correct |
4 ms |
9816 KB |
Ok |
24 |
Correct |
4 ms |
9820 KB |
Ok |
25 |
Correct |
3 ms |
9856 KB |
Ok |
26 |
Correct |
4 ms |
9820 KB |
Ok |
27 |
Correct |
4 ms |
9820 KB |
Ok |
28 |
Correct |
4 ms |
9820 KB |
Ok |
29 |
Correct |
5 ms |
10076 KB |
Ok |
30 |
Correct |
4 ms |
9816 KB |
Ok |
31 |
Correct |
4 ms |
9820 KB |
Ok |
32 |
Correct |
5 ms |
9824 KB |
Ok |
33 |
Correct |
4 ms |
9820 KB |
Ok |
34 |
Correct |
4 ms |
9820 KB |
Ok |
35 |
Correct |
4 ms |
9816 KB |
Ok |
36 |
Correct |
4 ms |
9820 KB |
Ok |
37 |
Correct |
4 ms |
9820 KB |
Ok |
38 |
Correct |
4 ms |
9824 KB |
Ok |
39 |
Correct |
72 ms |
28896 KB |
Ok |
40 |
Correct |
57 ms |
28232 KB |
Ok |
41 |
Correct |
103 ms |
32284 KB |
Ok |
42 |
Correct |
81 ms |
27644 KB |
Ok |
43 |
Correct |
53 ms |
22876 KB |
Ok |
44 |
Correct |
90 ms |
34824 KB |
Ok |
45 |
Correct |
5 ms |
9816 KB |
Ok |
46 |
Correct |
5 ms |
10072 KB |
Ok |
47 |
Correct |
5 ms |
9820 KB |
Ok |
48 |
Correct |
5 ms |
10000 KB |
Ok |
49 |
Correct |
5 ms |
9896 KB |
Ok |
50 |
Correct |
4 ms |
9820 KB |
Ok |
51 |
Correct |
4 ms |
9820 KB |
Ok |
52 |
Correct |
8 ms |
9940 KB |
Ok |
53 |
Correct |
5 ms |
9820 KB |
Ok |
54 |
Correct |
5 ms |
9820 KB |
Ok |
55 |
Correct |
6 ms |
10076 KB |
Ok |
56 |
Correct |
6 ms |
10332 KB |
Ok |
57 |
Correct |
6 ms |
10332 KB |
Ok |
58 |
Correct |
6 ms |
10332 KB |
Ok |
59 |
Correct |
6 ms |
10368 KB |
Ok |
60 |
Correct |
6 ms |
10072 KB |
Ok |
61 |
Correct |
9 ms |
10584 KB |
Ok |
62 |
Correct |
7 ms |
10328 KB |
Ok |
63 |
Correct |
6 ms |
10332 KB |
Ok |
64 |
Correct |
7 ms |
10332 KB |
Ok |
65 |
Correct |
48 ms |
15640 KB |
Ok |
66 |
Correct |
55 ms |
16164 KB |
Ok |
67 |
Correct |
52 ms |
15972 KB |
Ok |
68 |
Correct |
41 ms |
14736 KB |
Ok |
69 |
Correct |
49 ms |
15828 KB |
Ok |
70 |
Correct |
48 ms |
15336 KB |
Ok |
71 |
Correct |
44 ms |
14964 KB |
Ok |
72 |
Correct |
42 ms |
15304 KB |
Ok |
73 |
Correct |
58 ms |
16288 KB |
Ok |
74 |
Correct |
45 ms |
15068 KB |
Ok |
75 |
Correct |
55 ms |
15920 KB |
Ok |
76 |
Correct |
51 ms |
15852 KB |
Ok |
77 |
Correct |
47 ms |
15508 KB |
Ok |
78 |
Correct |
49 ms |
15252 KB |
Ok |
79 |
Correct |
50 ms |
15660 KB |
Ok |
80 |
Correct |
119 ms |
25924 KB |
Ok |
81 |
Correct |
114 ms |
25664 KB |
Ok |
82 |
Correct |
108 ms |
22936 KB |
Ok |
83 |
Correct |
101 ms |
25956 KB |
Ok |
84 |
Correct |
112 ms |
23336 KB |
Ok |
85 |
Correct |
117 ms |
24676 KB |
Ok |
86 |
Correct |
107 ms |
25448 KB |
Ok |
87 |
Correct |
116 ms |
25916 KB |
Ok |
88 |
Correct |
103 ms |
24268 KB |
Ok |
89 |
Correct |
112 ms |
25884 KB |
Ok |
90 |
Correct |
112 ms |
24616 KB |
Ok |
91 |
Correct |
99 ms |
23356 KB |
Ok |
92 |
Correct |
114 ms |
25660 KB |
Ok |
93 |
Correct |
108 ms |
24652 KB |
Ok |
94 |
Correct |
105 ms |
25908 KB |
Ok |
95 |
Correct |
125 ms |
24748 KB |
Ok |
96 |
Correct |
161 ms |
32136 KB |
Ok |
97 |
Correct |
164 ms |
28140 KB |
Ok |
98 |
Correct |
120 ms |
27308 KB |
Ok |
99 |
Correct |
152 ms |
28456 KB |
Ok |
100 |
Correct |
169 ms |
27920 KB |
Ok |
101 |
Correct |
143 ms |
30396 KB |
Ok |
102 |
Correct |
142 ms |
29356 KB |
Ok |
103 |
Correct |
144 ms |
29168 KB |
Ok |
104 |
Correct |
164 ms |
30712 KB |
Ok |
105 |
Correct |
161 ms |
32280 KB |
Ok |
106 |
Correct |
155 ms |
29940 KB |
Ok |
107 |
Correct |
172 ms |
31060 KB |
Ok |
108 |
Correct |
182 ms |
32488 KB |
Ok |
109 |
Correct |
155 ms |
31032 KB |
Ok |
110 |
Correct |
572 ms |
76528 KB |
Ok |
111 |
Correct |
678 ms |
77020 KB |
Ok |
112 |
Correct |
611 ms |
68224 KB |
Ok |
113 |
Correct |
648 ms |
76288 KB |
Ok |
114 |
Correct |
666 ms |
66344 KB |
Ok |
115 |
Correct |
686 ms |
76984 KB |
Ok |
116 |
Correct |
699 ms |
75500 KB |
Ok |
117 |
Correct |
658 ms |
77148 KB |
Ok |
118 |
Correct |
612 ms |
64420 KB |
Ok |
119 |
Correct |
777 ms |
76168 KB |
Ok |
120 |
Correct |
800 ms |
77300 KB |
Ok |
121 |
Correct |
747 ms |
73084 KB |
Ok |
122 |
Correct |
813 ms |
76744 KB |
Ok |
123 |
Correct |
661 ms |
72668 KB |
Ok |
124 |
Correct |
711 ms |
66800 KB |
Ok |
125 |
Correct |
342 ms |
61020 KB |
Ok |