#include <bits/stdc++.h>
using namespace std;
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1LL << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int n, m;
int len;
int timer = 0;
int vis[N], a[N];
void dfs(int u) {
if (u < 0 || u > len || vis[u])
return;
vis[u] = true;
dfs(u - n);
dfs(u + m);
a[u] = timer++;
}
void solve() {
cin >> n >> m;
len = n + m - 1 - __gcd(m, n);
timer = 0;
memset(vis, 0, sizeof vis);
for (int i = 0; i <= len; ++i)
dfs(i);
cout << len << '\n';
for (int i = 0; i < len; ++i) {
cout << a[i] - a[i + 1] << ' ';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
2 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5980 KB |
Ok |
4 |
Correct |
3 ms |
5976 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
2 ms |
5976 KB |
Ok |
7 |
Correct |
2 ms |
5976 KB |
Ok |
8 |
Correct |
2 ms |
5976 KB |
Ok |
9 |
Correct |
2 ms |
5976 KB |
Ok |
10 |
Correct |
3 ms |
6232 KB |
Ok |
11 |
Correct |
2 ms |
5976 KB |
Ok |
12 |
Correct |
2 ms |
5976 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
3 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5976 KB |
Ok |
4 |
Correct |
2 ms |
5976 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
3 ms |
5976 KB |
Ok |
7 |
Correct |
7 ms |
6488 KB |
Ok |
8 |
Correct |
4 ms |
6236 KB |
Ok |
9 |
Correct |
8 ms |
6744 KB |
Ok |
10 |
Correct |
6 ms |
6232 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
2 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5976 KB |
Ok |
4 |
Correct |
2 ms |
5976 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
2 ms |
5980 KB |
Ok |
7 |
Correct |
2 ms |
5976 KB |
Ok |
8 |
Correct |
2 ms |
5980 KB |
Ok |
9 |
Correct |
2 ms |
5976 KB |
Ok |
10 |
Correct |
2 ms |
5976 KB |
Ok |
11 |
Correct |
2 ms |
5980 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
2 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5976 KB |
Ok |
4 |
Correct |
2 ms |
5980 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
50 ms |
16468 KB |
Ok |
7 |
Correct |
41 ms |
14928 KB |
Ok |
8 |
Correct |
83 ms |
18056 KB |
Ok |
9 |
Correct |
82 ms |
16484 KB |
Ok |
10 |
Correct |
39 ms |
13648 KB |
Ok |
11 |
Correct |
64 ms |
19148 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
2 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5980 KB |
Ok |
4 |
Correct |
3 ms |
5976 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
2 ms |
5976 KB |
Ok |
7 |
Correct |
2 ms |
5976 KB |
Ok |
8 |
Correct |
2 ms |
5976 KB |
Ok |
9 |
Correct |
2 ms |
5976 KB |
Ok |
10 |
Correct |
3 ms |
6232 KB |
Ok |
11 |
Correct |
2 ms |
5976 KB |
Ok |
12 |
Correct |
2 ms |
5976 KB |
Ok |
13 |
Correct |
2 ms |
5976 KB |
Ok |
14 |
Correct |
2 ms |
5976 KB |
Ok |
15 |
Correct |
2 ms |
5976 KB |
Ok |
16 |
Correct |
2 ms |
5976 KB |
Ok |
17 |
Correct |
2 ms |
5976 KB |
Ok |
18 |
Correct |
2 ms |
5980 KB |
Ok |
19 |
Correct |
2 ms |
5976 KB |
Ok |
20 |
Correct |
2 ms |
5980 KB |
Ok |
21 |
Correct |
2 ms |
5976 KB |
Ok |
22 |
Correct |
2 ms |
5976 KB |
Ok |
23 |
Correct |
2 ms |
5980 KB |
Ok |
24 |
Correct |
4 ms |
5976 KB |
Ok |
25 |
Correct |
3 ms |
5980 KB |
Ok |
26 |
Correct |
3 ms |
6176 KB |
Ok |
27 |
Correct |
3 ms |
5976 KB |
Ok |
28 |
Correct |
3 ms |
5976 KB |
Ok |
29 |
Correct |
3 ms |
5976 KB |
Ok |
30 |
Correct |
3 ms |
5976 KB |
Ok |
31 |
Correct |
3 ms |
5976 KB |
Ok |
32 |
Correct |
3 ms |
5976 KB |
Ok |
33 |
Correct |
4 ms |
5976 KB |
Ok |
34 |
Correct |
4 ms |
6232 KB |
Ok |
35 |
Correct |
4 ms |
6236 KB |
Ok |
36 |
Correct |
4 ms |
6232 KB |
Ok |
37 |
Correct |
4 ms |
6232 KB |
Ok |
38 |
Correct |
6 ms |
6232 KB |
Ok |
39 |
Correct |
4 ms |
6236 KB |
Ok |
40 |
Correct |
4 ms |
6232 KB |
Ok |
41 |
Correct |
4 ms |
6236 KB |
Ok |
42 |
Correct |
4 ms |
6236 KB |
Ok |
43 |
Correct |
4 ms |
6232 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
2 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5980 KB |
Ok |
4 |
Correct |
3 ms |
5976 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
2 ms |
5976 KB |
Ok |
7 |
Correct |
2 ms |
5976 KB |
Ok |
8 |
Correct |
2 ms |
5976 KB |
Ok |
9 |
Correct |
2 ms |
5976 KB |
Ok |
10 |
Correct |
3 ms |
6232 KB |
Ok |
11 |
Correct |
2 ms |
5976 KB |
Ok |
12 |
Correct |
2 ms |
5976 KB |
Ok |
13 |
Correct |
2 ms |
5976 KB |
Ok |
14 |
Correct |
3 ms |
5976 KB |
Ok |
15 |
Correct |
2 ms |
5976 KB |
Ok |
16 |
Correct |
2 ms |
5976 KB |
Ok |
17 |
Correct |
2 ms |
5976 KB |
Ok |
18 |
Correct |
3 ms |
5976 KB |
Ok |
19 |
Correct |
7 ms |
6488 KB |
Ok |
20 |
Correct |
4 ms |
6236 KB |
Ok |
21 |
Correct |
8 ms |
6744 KB |
Ok |
22 |
Correct |
6 ms |
6232 KB |
Ok |
23 |
Correct |
2 ms |
5976 KB |
Ok |
24 |
Correct |
2 ms |
5976 KB |
Ok |
25 |
Correct |
2 ms |
5976 KB |
Ok |
26 |
Correct |
2 ms |
5976 KB |
Ok |
27 |
Correct |
2 ms |
5976 KB |
Ok |
28 |
Correct |
2 ms |
5980 KB |
Ok |
29 |
Correct |
2 ms |
5976 KB |
Ok |
30 |
Correct |
2 ms |
5980 KB |
Ok |
31 |
Correct |
2 ms |
5976 KB |
Ok |
32 |
Correct |
2 ms |
5976 KB |
Ok |
33 |
Correct |
2 ms |
5980 KB |
Ok |
34 |
Correct |
4 ms |
5976 KB |
Ok |
35 |
Correct |
3 ms |
5980 KB |
Ok |
36 |
Correct |
3 ms |
6176 KB |
Ok |
37 |
Correct |
3 ms |
5976 KB |
Ok |
38 |
Correct |
3 ms |
5976 KB |
Ok |
39 |
Correct |
3 ms |
5976 KB |
Ok |
40 |
Correct |
3 ms |
5976 KB |
Ok |
41 |
Correct |
3 ms |
5976 KB |
Ok |
42 |
Correct |
3 ms |
5976 KB |
Ok |
43 |
Correct |
4 ms |
5976 KB |
Ok |
44 |
Correct |
4 ms |
6232 KB |
Ok |
45 |
Correct |
4 ms |
6236 KB |
Ok |
46 |
Correct |
4 ms |
6232 KB |
Ok |
47 |
Correct |
4 ms |
6232 KB |
Ok |
48 |
Correct |
6 ms |
6232 KB |
Ok |
49 |
Correct |
4 ms |
6236 KB |
Ok |
50 |
Correct |
4 ms |
6232 KB |
Ok |
51 |
Correct |
4 ms |
6236 KB |
Ok |
52 |
Correct |
4 ms |
6236 KB |
Ok |
53 |
Correct |
4 ms |
6232 KB |
Ok |
54 |
Correct |
36 ms |
10336 KB |
Ok |
55 |
Correct |
43 ms |
10832 KB |
Ok |
56 |
Correct |
44 ms |
10576 KB |
Ok |
57 |
Correct |
35 ms |
9808 KB |
Ok |
58 |
Correct |
39 ms |
10576 KB |
Ok |
59 |
Correct |
43 ms |
10580 KB |
Ok |
60 |
Correct |
36 ms |
10064 KB |
Ok |
61 |
Correct |
33 ms |
10064 KB |
Ok |
62 |
Correct |
44 ms |
10832 KB |
Ok |
63 |
Correct |
35 ms |
10320 KB |
Ok |
64 |
Correct |
42 ms |
10832 KB |
Ok |
65 |
Correct |
41 ms |
10576 KB |
Ok |
66 |
Correct |
37 ms |
10320 KB |
Ok |
67 |
Correct |
33 ms |
10064 KB |
Ok |
68 |
Correct |
38 ms |
10580 KB |
Ok |
69 |
Correct |
68 ms |
17444 KB |
Ok |
70 |
Correct |
68 ms |
17488 KB |
Ok |
71 |
Correct |
66 ms |
15952 KB |
Ok |
72 |
Correct |
70 ms |
17232 KB |
Ok |
73 |
Correct |
65 ms |
16192 KB |
Ok |
74 |
Correct |
67 ms |
16720 KB |
Ok |
75 |
Correct |
66 ms |
16980 KB |
Ok |
76 |
Correct |
65 ms |
17212 KB |
Ok |
77 |
Correct |
78 ms |
16928 KB |
Ok |
78 |
Correct |
76 ms |
17232 KB |
Ok |
79 |
Correct |
80 ms |
17028 KB |
Ok |
80 |
Correct |
67 ms |
15952 KB |
Ok |
81 |
Correct |
78 ms |
17524 KB |
Ok |
82 |
Correct |
71 ms |
16708 KB |
Ok |
83 |
Correct |
71 ms |
17580 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Ok |
2 |
Correct |
2 ms |
5976 KB |
Ok |
3 |
Correct |
2 ms |
5980 KB |
Ok |
4 |
Correct |
3 ms |
5976 KB |
Ok |
5 |
Correct |
2 ms |
5976 KB |
Ok |
6 |
Correct |
2 ms |
5976 KB |
Ok |
7 |
Correct |
2 ms |
5976 KB |
Ok |
8 |
Correct |
2 ms |
5976 KB |
Ok |
9 |
Correct |
2 ms |
5976 KB |
Ok |
10 |
Correct |
3 ms |
6232 KB |
Ok |
11 |
Correct |
2 ms |
5976 KB |
Ok |
12 |
Correct |
2 ms |
5976 KB |
Ok |
13 |
Correct |
2 ms |
5976 KB |
Ok |
14 |
Correct |
3 ms |
5976 KB |
Ok |
15 |
Correct |
2 ms |
5976 KB |
Ok |
16 |
Correct |
2 ms |
5976 KB |
Ok |
17 |
Correct |
2 ms |
5976 KB |
Ok |
18 |
Correct |
3 ms |
5976 KB |
Ok |
19 |
Correct |
7 ms |
6488 KB |
Ok |
20 |
Correct |
4 ms |
6236 KB |
Ok |
21 |
Correct |
8 ms |
6744 KB |
Ok |
22 |
Correct |
6 ms |
6232 KB |
Ok |
23 |
Correct |
2 ms |
5976 KB |
Ok |
24 |
Correct |
2 ms |
5976 KB |
Ok |
25 |
Correct |
2 ms |
5976 KB |
Ok |
26 |
Correct |
2 ms |
5976 KB |
Ok |
27 |
Correct |
2 ms |
5976 KB |
Ok |
28 |
Correct |
2 ms |
5980 KB |
Ok |
29 |
Correct |
2 ms |
5976 KB |
Ok |
30 |
Correct |
2 ms |
5980 KB |
Ok |
31 |
Correct |
2 ms |
5976 KB |
Ok |
32 |
Correct |
2 ms |
5976 KB |
Ok |
33 |
Correct |
2 ms |
5980 KB |
Ok |
34 |
Correct |
2 ms |
5976 KB |
Ok |
35 |
Correct |
2 ms |
5976 KB |
Ok |
36 |
Correct |
2 ms |
5976 KB |
Ok |
37 |
Correct |
2 ms |
5980 KB |
Ok |
38 |
Correct |
2 ms |
5976 KB |
Ok |
39 |
Correct |
50 ms |
16468 KB |
Ok |
40 |
Correct |
41 ms |
14928 KB |
Ok |
41 |
Correct |
83 ms |
18056 KB |
Ok |
42 |
Correct |
82 ms |
16484 KB |
Ok |
43 |
Correct |
39 ms |
13648 KB |
Ok |
44 |
Correct |
64 ms |
19148 KB |
Ok |
45 |
Correct |
4 ms |
5976 KB |
Ok |
46 |
Correct |
3 ms |
5980 KB |
Ok |
47 |
Correct |
3 ms |
6176 KB |
Ok |
48 |
Correct |
3 ms |
5976 KB |
Ok |
49 |
Correct |
3 ms |
5976 KB |
Ok |
50 |
Correct |
3 ms |
5976 KB |
Ok |
51 |
Correct |
3 ms |
5976 KB |
Ok |
52 |
Correct |
3 ms |
5976 KB |
Ok |
53 |
Correct |
3 ms |
5976 KB |
Ok |
54 |
Correct |
4 ms |
5976 KB |
Ok |
55 |
Correct |
4 ms |
6232 KB |
Ok |
56 |
Correct |
4 ms |
6236 KB |
Ok |
57 |
Correct |
4 ms |
6232 KB |
Ok |
58 |
Correct |
4 ms |
6232 KB |
Ok |
59 |
Correct |
6 ms |
6232 KB |
Ok |
60 |
Correct |
4 ms |
6236 KB |
Ok |
61 |
Correct |
4 ms |
6232 KB |
Ok |
62 |
Correct |
4 ms |
6236 KB |
Ok |
63 |
Correct |
4 ms |
6236 KB |
Ok |
64 |
Correct |
4 ms |
6232 KB |
Ok |
65 |
Correct |
36 ms |
10336 KB |
Ok |
66 |
Correct |
43 ms |
10832 KB |
Ok |
67 |
Correct |
44 ms |
10576 KB |
Ok |
68 |
Correct |
35 ms |
9808 KB |
Ok |
69 |
Correct |
39 ms |
10576 KB |
Ok |
70 |
Correct |
43 ms |
10580 KB |
Ok |
71 |
Correct |
36 ms |
10064 KB |
Ok |
72 |
Correct |
33 ms |
10064 KB |
Ok |
73 |
Correct |
44 ms |
10832 KB |
Ok |
74 |
Correct |
35 ms |
10320 KB |
Ok |
75 |
Correct |
42 ms |
10832 KB |
Ok |
76 |
Correct |
41 ms |
10576 KB |
Ok |
77 |
Correct |
37 ms |
10320 KB |
Ok |
78 |
Correct |
33 ms |
10064 KB |
Ok |
79 |
Correct |
38 ms |
10580 KB |
Ok |
80 |
Correct |
68 ms |
17444 KB |
Ok |
81 |
Correct |
68 ms |
17488 KB |
Ok |
82 |
Correct |
66 ms |
15952 KB |
Ok |
83 |
Correct |
70 ms |
17232 KB |
Ok |
84 |
Correct |
65 ms |
16192 KB |
Ok |
85 |
Correct |
67 ms |
16720 KB |
Ok |
86 |
Correct |
66 ms |
16980 KB |
Ok |
87 |
Correct |
65 ms |
17212 KB |
Ok |
88 |
Correct |
78 ms |
16928 KB |
Ok |
89 |
Correct |
76 ms |
17232 KB |
Ok |
90 |
Correct |
80 ms |
17028 KB |
Ok |
91 |
Correct |
67 ms |
15952 KB |
Ok |
92 |
Correct |
78 ms |
17524 KB |
Ok |
93 |
Correct |
71 ms |
16708 KB |
Ok |
94 |
Correct |
71 ms |
17580 KB |
Ok |
95 |
Correct |
91 ms |
13780 KB |
Ok |
96 |
Correct |
129 ms |
16564 KB |
Ok |
97 |
Correct |
128 ms |
15920 KB |
Ok |
98 |
Correct |
97 ms |
14160 KB |
Ok |
99 |
Correct |
116 ms |
14932 KB |
Ok |
100 |
Correct |
116 ms |
15856 KB |
Ok |
101 |
Correct |
134 ms |
15036 KB |
Ok |
102 |
Correct |
121 ms |
15440 KB |
Ok |
103 |
Correct |
117 ms |
15560 KB |
Ok |
104 |
Correct |
137 ms |
16464 KB |
Ok |
105 |
Correct |
142 ms |
16408 KB |
Ok |
106 |
Correct |
107 ms |
14672 KB |
Ok |
107 |
Correct |
122 ms |
15696 KB |
Ok |
108 |
Correct |
133 ms |
16976 KB |
Ok |
109 |
Correct |
121 ms |
15620 KB |
Ok |
110 |
Correct |
275 ms |
46928 KB |
Ok |
111 |
Correct |
287 ms |
47672 KB |
Ok |
112 |
Correct |
265 ms |
43344 KB |
Ok |
113 |
Correct |
280 ms |
46696 KB |
Ok |
114 |
Correct |
276 ms |
42816 KB |
Ok |
115 |
Correct |
281 ms |
47648 KB |
Ok |
116 |
Correct |
293 ms |
47128 KB |
Ok |
117 |
Correct |
272 ms |
47440 KB |
Ok |
118 |
Correct |
286 ms |
41856 KB |
Ok |
119 |
Correct |
278 ms |
46760 KB |
Ok |
120 |
Correct |
267 ms |
47444 KB |
Ok |
121 |
Correct |
282 ms |
45244 KB |
Ok |
122 |
Correct |
265 ms |
47440 KB |
Ok |
123 |
Correct |
279 ms |
45488 KB |
Ok |
124 |
Correct |
295 ms |
43088 KB |
Ok |
125 |
Correct |
230 ms |
30800 KB |
Ok |