#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz size()
#define ft first
#define sd second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef unsigned long long ull;
const int N = 5e5 + 5;
const ll M = 1e8;
const ll inf = 1e9;
const ll mod = 1e9;
const double Pi = acos(-1);
ll binpow(ll x, ll ti) { ll res = 1;while (ti){if(ti & 1)res *= x;x *= x;ti >>= 1; x %= mod; res %= mod;} return res;}
ll binmul(ll x, ll ti) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= mod; res %= mod;} return res;}
ll nok(ll a, ll b) { return (a*b)/__gcd(abs(a),abs(b)) * (a*b > 0 ? 1 : -1); }
bool odd(ll n) { return (n % 2 == 1); }
bool even(ll n) { return (n % 2 == 0); }
int n, m, used[N], pr[N], len;
vector <int> g[N], order;
bool ok;
void qfs(int v, int mx) {
used[v] = 1;
for (auto to : g[v]) {
if (to > mx || used[to]) continue;
qfs(to, mx);
}
order.pb(v);
}
const void solve(/*Armashka*/) {
cin >> n >> m;
ll len = n + m - 1 - __gcd(n, m);
for (int i = 0; i <= len; ++ i) used[i] = 0;
for (int i = 0; i <= len; ++ i) {
if (i >= n) g[i - n].pb(i);
if (i >= m) g[i].pb(i - m);
}
for (int i = 0; i <= len; ++ i) {
if (!used[i]) qfs(i, len);
}
reverse(all(order));
for (int i = 0; i <= len; ++ i) {
pr[order[i]] = i;
}
cout << len << "\n";
for (int i = 1; i <= len; ++ i) {
cout << -(pr[i] - pr[i - 1]) << " ";
}
cout << "\n";
for (int i = 0; i <= len; ++ i) pr[i] = 0, g[i].clear();
order.clear();
}
signed main() {
fast;
//freopen("divide.in", "r", stdin);
//freopen("divide.out", "w", stdout);
int tt = 1;
cin >> tt;
while (tt --) {
solve();
}
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Ok |
2 |
Correct |
7 ms |
11980 KB |
Ok |
3 |
Correct |
7 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
8 ms |
11980 KB |
Ok |
6 |
Correct |
7 ms |
12024 KB |
Ok |
7 |
Correct |
7 ms |
11980 KB |
Ok |
8 |
Correct |
7 ms |
11980 KB |
Ok |
9 |
Correct |
7 ms |
11980 KB |
Ok |
10 |
Correct |
6 ms |
11980 KB |
Ok |
11 |
Correct |
6 ms |
11980 KB |
Ok |
12 |
Correct |
6 ms |
11980 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11992 KB |
Ok |
2 |
Correct |
6 ms |
12076 KB |
Ok |
3 |
Correct |
6 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
6 ms |
11980 KB |
Ok |
6 |
Correct |
10 ms |
12196 KB |
Ok |
7 |
Correct |
16 ms |
13068 KB |
Ok |
8 |
Correct |
10 ms |
12492 KB |
Ok |
9 |
Correct |
20 ms |
13320 KB |
Ok |
10 |
Correct |
12 ms |
12740 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Ok |
2 |
Correct |
6 ms |
12016 KB |
Ok |
3 |
Correct |
7 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
6 ms |
11980 KB |
Ok |
6 |
Correct |
7 ms |
12064 KB |
Ok |
7 |
Correct |
6 ms |
12072 KB |
Ok |
8 |
Correct |
6 ms |
12004 KB |
Ok |
9 |
Correct |
6 ms |
11980 KB |
Ok |
10 |
Correct |
6 ms |
12036 KB |
Ok |
11 |
Correct |
6 ms |
11980 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11980 KB |
Ok |
2 |
Correct |
6 ms |
11972 KB |
Ok |
3 |
Correct |
6 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
7 ms |
11980 KB |
Ok |
6 |
Correct |
128 ms |
26540 KB |
Ok |
7 |
Correct |
87 ms |
34924 KB |
Ok |
8 |
Correct |
169 ms |
37512 KB |
Ok |
9 |
Correct |
117 ms |
34412 KB |
Ok |
10 |
Correct |
90 ms |
23672 KB |
Ok |
11 |
Correct |
121 ms |
30012 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Ok |
2 |
Correct |
7 ms |
11980 KB |
Ok |
3 |
Correct |
7 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
8 ms |
11980 KB |
Ok |
6 |
Correct |
7 ms |
12024 KB |
Ok |
7 |
Correct |
7 ms |
11980 KB |
Ok |
8 |
Correct |
7 ms |
11980 KB |
Ok |
9 |
Correct |
7 ms |
11980 KB |
Ok |
10 |
Correct |
6 ms |
11980 KB |
Ok |
11 |
Correct |
6 ms |
11980 KB |
Ok |
12 |
Correct |
6 ms |
11980 KB |
Ok |
13 |
Correct |
7 ms |
11980 KB |
Ok |
14 |
Correct |
6 ms |
12016 KB |
Ok |
15 |
Correct |
7 ms |
11980 KB |
Ok |
16 |
Correct |
6 ms |
11980 KB |
Ok |
17 |
Correct |
6 ms |
11980 KB |
Ok |
18 |
Correct |
7 ms |
12064 KB |
Ok |
19 |
Correct |
6 ms |
12072 KB |
Ok |
20 |
Correct |
6 ms |
12004 KB |
Ok |
21 |
Correct |
6 ms |
11980 KB |
Ok |
22 |
Correct |
6 ms |
12036 KB |
Ok |
23 |
Correct |
6 ms |
11980 KB |
Ok |
24 |
Correct |
8 ms |
12236 KB |
Ok |
25 |
Correct |
8 ms |
12236 KB |
Ok |
26 |
Correct |
8 ms |
12236 KB |
Ok |
27 |
Correct |
8 ms |
12236 KB |
Ok |
28 |
Correct |
8 ms |
12108 KB |
Ok |
29 |
Correct |
7 ms |
12200 KB |
Ok |
30 |
Correct |
7 ms |
12108 KB |
Ok |
31 |
Correct |
8 ms |
12236 KB |
Ok |
32 |
Correct |
8 ms |
12236 KB |
Ok |
33 |
Correct |
10 ms |
12236 KB |
Ok |
34 |
Correct |
12 ms |
12492 KB |
Ok |
35 |
Correct |
11 ms |
12540 KB |
Ok |
36 |
Correct |
12 ms |
12472 KB |
Ok |
37 |
Correct |
9 ms |
12572 KB |
Ok |
38 |
Correct |
10 ms |
12492 KB |
Ok |
39 |
Correct |
10 ms |
12364 KB |
Ok |
40 |
Correct |
10 ms |
12492 KB |
Ok |
41 |
Correct |
9 ms |
12492 KB |
Ok |
42 |
Correct |
10 ms |
12364 KB |
Ok |
43 |
Correct |
11 ms |
12620 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Ok |
2 |
Correct |
7 ms |
11980 KB |
Ok |
3 |
Correct |
7 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
8 ms |
11980 KB |
Ok |
6 |
Correct |
7 ms |
12024 KB |
Ok |
7 |
Correct |
7 ms |
11980 KB |
Ok |
8 |
Correct |
7 ms |
11980 KB |
Ok |
9 |
Correct |
7 ms |
11980 KB |
Ok |
10 |
Correct |
6 ms |
11980 KB |
Ok |
11 |
Correct |
6 ms |
11980 KB |
Ok |
12 |
Correct |
6 ms |
11980 KB |
Ok |
13 |
Correct |
7 ms |
11992 KB |
Ok |
14 |
Correct |
6 ms |
12076 KB |
Ok |
15 |
Correct |
6 ms |
11980 KB |
Ok |
16 |
Correct |
6 ms |
11980 KB |
Ok |
17 |
Correct |
6 ms |
11980 KB |
Ok |
18 |
Correct |
10 ms |
12196 KB |
Ok |
19 |
Correct |
16 ms |
13068 KB |
Ok |
20 |
Correct |
10 ms |
12492 KB |
Ok |
21 |
Correct |
20 ms |
13320 KB |
Ok |
22 |
Correct |
12 ms |
12740 KB |
Ok |
23 |
Correct |
7 ms |
11980 KB |
Ok |
24 |
Correct |
6 ms |
12016 KB |
Ok |
25 |
Correct |
7 ms |
11980 KB |
Ok |
26 |
Correct |
6 ms |
11980 KB |
Ok |
27 |
Correct |
6 ms |
11980 KB |
Ok |
28 |
Correct |
7 ms |
12064 KB |
Ok |
29 |
Correct |
6 ms |
12072 KB |
Ok |
30 |
Correct |
6 ms |
12004 KB |
Ok |
31 |
Correct |
6 ms |
11980 KB |
Ok |
32 |
Correct |
6 ms |
12036 KB |
Ok |
33 |
Correct |
6 ms |
11980 KB |
Ok |
34 |
Correct |
8 ms |
12236 KB |
Ok |
35 |
Correct |
8 ms |
12236 KB |
Ok |
36 |
Correct |
8 ms |
12236 KB |
Ok |
37 |
Correct |
8 ms |
12236 KB |
Ok |
38 |
Correct |
8 ms |
12108 KB |
Ok |
39 |
Correct |
7 ms |
12200 KB |
Ok |
40 |
Correct |
7 ms |
12108 KB |
Ok |
41 |
Correct |
8 ms |
12236 KB |
Ok |
42 |
Correct |
8 ms |
12236 KB |
Ok |
43 |
Correct |
10 ms |
12236 KB |
Ok |
44 |
Correct |
12 ms |
12492 KB |
Ok |
45 |
Correct |
11 ms |
12540 KB |
Ok |
46 |
Correct |
12 ms |
12472 KB |
Ok |
47 |
Correct |
9 ms |
12572 KB |
Ok |
48 |
Correct |
10 ms |
12492 KB |
Ok |
49 |
Correct |
10 ms |
12364 KB |
Ok |
50 |
Correct |
10 ms |
12492 KB |
Ok |
51 |
Correct |
9 ms |
12492 KB |
Ok |
52 |
Correct |
10 ms |
12364 KB |
Ok |
53 |
Correct |
11 ms |
12620 KB |
Ok |
54 |
Correct |
74 ms |
17696 KB |
Ok |
55 |
Correct |
85 ms |
17960 KB |
Ok |
56 |
Correct |
77 ms |
17984 KB |
Ok |
57 |
Correct |
59 ms |
16920 KB |
Ok |
58 |
Correct |
77 ms |
17432 KB |
Ok |
59 |
Correct |
66 ms |
17044 KB |
Ok |
60 |
Correct |
59 ms |
16604 KB |
Ok |
61 |
Correct |
71 ms |
17268 KB |
Ok |
62 |
Correct |
88 ms |
17700 KB |
Ok |
63 |
Correct |
63 ms |
17044 KB |
Ok |
64 |
Correct |
76 ms |
17968 KB |
Ok |
65 |
Correct |
79 ms |
17596 KB |
Ok |
66 |
Correct |
68 ms |
17356 KB |
Ok |
67 |
Correct |
62 ms |
17192 KB |
Ok |
68 |
Correct |
78 ms |
17448 KB |
Ok |
69 |
Correct |
165 ms |
28348 KB |
Ok |
70 |
Correct |
203 ms |
29060 KB |
Ok |
71 |
Correct |
171 ms |
28376 KB |
Ok |
72 |
Correct |
171 ms |
28496 KB |
Ok |
73 |
Correct |
158 ms |
27576 KB |
Ok |
74 |
Correct |
169 ms |
27272 KB |
Ok |
75 |
Correct |
197 ms |
27640 KB |
Ok |
76 |
Correct |
169 ms |
28628 KB |
Ok |
77 |
Correct |
170 ms |
26776 KB |
Ok |
78 |
Correct |
154 ms |
27060 KB |
Ok |
79 |
Correct |
165 ms |
28216 KB |
Ok |
80 |
Correct |
192 ms |
28296 KB |
Ok |
81 |
Correct |
181 ms |
27360 KB |
Ok |
82 |
Correct |
173 ms |
27964 KB |
Ok |
83 |
Correct |
160 ms |
27504 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Ok |
2 |
Correct |
7 ms |
11980 KB |
Ok |
3 |
Correct |
7 ms |
11980 KB |
Ok |
4 |
Correct |
6 ms |
11980 KB |
Ok |
5 |
Correct |
8 ms |
11980 KB |
Ok |
6 |
Correct |
7 ms |
12024 KB |
Ok |
7 |
Correct |
7 ms |
11980 KB |
Ok |
8 |
Correct |
7 ms |
11980 KB |
Ok |
9 |
Correct |
7 ms |
11980 KB |
Ok |
10 |
Correct |
6 ms |
11980 KB |
Ok |
11 |
Correct |
6 ms |
11980 KB |
Ok |
12 |
Correct |
6 ms |
11980 KB |
Ok |
13 |
Correct |
7 ms |
11992 KB |
Ok |
14 |
Correct |
6 ms |
12076 KB |
Ok |
15 |
Correct |
6 ms |
11980 KB |
Ok |
16 |
Correct |
6 ms |
11980 KB |
Ok |
17 |
Correct |
6 ms |
11980 KB |
Ok |
18 |
Correct |
10 ms |
12196 KB |
Ok |
19 |
Correct |
16 ms |
13068 KB |
Ok |
20 |
Correct |
10 ms |
12492 KB |
Ok |
21 |
Correct |
20 ms |
13320 KB |
Ok |
22 |
Correct |
12 ms |
12740 KB |
Ok |
23 |
Correct |
7 ms |
11980 KB |
Ok |
24 |
Correct |
6 ms |
12016 KB |
Ok |
25 |
Correct |
7 ms |
11980 KB |
Ok |
26 |
Correct |
6 ms |
11980 KB |
Ok |
27 |
Correct |
6 ms |
11980 KB |
Ok |
28 |
Correct |
7 ms |
12064 KB |
Ok |
29 |
Correct |
6 ms |
12072 KB |
Ok |
30 |
Correct |
6 ms |
12004 KB |
Ok |
31 |
Correct |
6 ms |
11980 KB |
Ok |
32 |
Correct |
6 ms |
12036 KB |
Ok |
33 |
Correct |
6 ms |
11980 KB |
Ok |
34 |
Correct |
6 ms |
11980 KB |
Ok |
35 |
Correct |
6 ms |
11972 KB |
Ok |
36 |
Correct |
6 ms |
11980 KB |
Ok |
37 |
Correct |
6 ms |
11980 KB |
Ok |
38 |
Correct |
7 ms |
11980 KB |
Ok |
39 |
Correct |
128 ms |
26540 KB |
Ok |
40 |
Correct |
87 ms |
34924 KB |
Ok |
41 |
Correct |
169 ms |
37512 KB |
Ok |
42 |
Correct |
117 ms |
34412 KB |
Ok |
43 |
Correct |
90 ms |
23672 KB |
Ok |
44 |
Correct |
121 ms |
30012 KB |
Ok |
45 |
Correct |
8 ms |
12236 KB |
Ok |
46 |
Correct |
8 ms |
12236 KB |
Ok |
47 |
Correct |
8 ms |
12236 KB |
Ok |
48 |
Correct |
8 ms |
12236 KB |
Ok |
49 |
Correct |
8 ms |
12108 KB |
Ok |
50 |
Correct |
7 ms |
12200 KB |
Ok |
51 |
Correct |
7 ms |
12108 KB |
Ok |
52 |
Correct |
8 ms |
12236 KB |
Ok |
53 |
Correct |
8 ms |
12236 KB |
Ok |
54 |
Correct |
10 ms |
12236 KB |
Ok |
55 |
Correct |
12 ms |
12492 KB |
Ok |
56 |
Correct |
11 ms |
12540 KB |
Ok |
57 |
Correct |
12 ms |
12472 KB |
Ok |
58 |
Correct |
9 ms |
12572 KB |
Ok |
59 |
Correct |
10 ms |
12492 KB |
Ok |
60 |
Correct |
10 ms |
12364 KB |
Ok |
61 |
Correct |
10 ms |
12492 KB |
Ok |
62 |
Correct |
9 ms |
12492 KB |
Ok |
63 |
Correct |
10 ms |
12364 KB |
Ok |
64 |
Correct |
11 ms |
12620 KB |
Ok |
65 |
Correct |
74 ms |
17696 KB |
Ok |
66 |
Correct |
85 ms |
17960 KB |
Ok |
67 |
Correct |
77 ms |
17984 KB |
Ok |
68 |
Correct |
59 ms |
16920 KB |
Ok |
69 |
Correct |
77 ms |
17432 KB |
Ok |
70 |
Correct |
66 ms |
17044 KB |
Ok |
71 |
Correct |
59 ms |
16604 KB |
Ok |
72 |
Correct |
71 ms |
17268 KB |
Ok |
73 |
Correct |
88 ms |
17700 KB |
Ok |
74 |
Correct |
63 ms |
17044 KB |
Ok |
75 |
Correct |
76 ms |
17968 KB |
Ok |
76 |
Correct |
79 ms |
17596 KB |
Ok |
77 |
Correct |
68 ms |
17356 KB |
Ok |
78 |
Correct |
62 ms |
17192 KB |
Ok |
79 |
Correct |
78 ms |
17448 KB |
Ok |
80 |
Correct |
165 ms |
28348 KB |
Ok |
81 |
Correct |
203 ms |
29060 KB |
Ok |
82 |
Correct |
171 ms |
28376 KB |
Ok |
83 |
Correct |
171 ms |
28496 KB |
Ok |
84 |
Correct |
158 ms |
27576 KB |
Ok |
85 |
Correct |
169 ms |
27272 KB |
Ok |
86 |
Correct |
197 ms |
27640 KB |
Ok |
87 |
Correct |
169 ms |
28628 KB |
Ok |
88 |
Correct |
170 ms |
26776 KB |
Ok |
89 |
Correct |
154 ms |
27060 KB |
Ok |
90 |
Correct |
165 ms |
28216 KB |
Ok |
91 |
Correct |
192 ms |
28296 KB |
Ok |
92 |
Correct |
181 ms |
27360 KB |
Ok |
93 |
Correct |
173 ms |
27964 KB |
Ok |
94 |
Correct |
160 ms |
27504 KB |
Ok |
95 |
Correct |
170 ms |
26608 KB |
Ok |
96 |
Correct |
257 ms |
32960 KB |
Ok |
97 |
Correct |
286 ms |
29228 KB |
Ok |
98 |
Correct |
229 ms |
29372 KB |
Ok |
99 |
Correct |
222 ms |
28764 KB |
Ok |
100 |
Correct |
208 ms |
28300 KB |
Ok |
101 |
Correct |
225 ms |
31464 KB |
Ok |
102 |
Correct |
208 ms |
29404 KB |
Ok |
103 |
Correct |
225 ms |
30432 KB |
Ok |
104 |
Correct |
280 ms |
32384 KB |
Ok |
105 |
Correct |
246 ms |
32752 KB |
Ok |
106 |
Correct |
216 ms |
32988 KB |
Ok |
107 |
Correct |
253 ms |
31704 KB |
Ok |
108 |
Correct |
281 ms |
32616 KB |
Ok |
109 |
Correct |
279 ms |
33916 KB |
Ok |
110 |
Correct |
989 ms |
77328 KB |
Ok |
111 |
Correct |
1153 ms |
79404 KB |
Ok |
112 |
Correct |
1098 ms |
74256 KB |
Ok |
113 |
Correct |
1044 ms |
80480 KB |
Ok |
114 |
Correct |
1058 ms |
79344 KB |
Ok |
115 |
Correct |
1045 ms |
76420 KB |
Ok |
116 |
Correct |
1075 ms |
79520 KB |
Ok |
117 |
Correct |
946 ms |
79272 KB |
Ok |
118 |
Correct |
1127 ms |
79892 KB |
Ok |
119 |
Correct |
1118 ms |
78228 KB |
Ok |
120 |
Correct |
1058 ms |
78336 KB |
Ok |
121 |
Correct |
1117 ms |
78660 KB |
Ok |
122 |
Correct |
994 ms |
77120 KB |
Ok |
123 |
Correct |
1210 ms |
79808 KB |
Ok |
124 |
Correct |
979 ms |
72636 KB |
Ok |
125 |
Correct |
410 ms |
64396 KB |
Ok |