#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#pragma GCC optimize("Ofast","O3","unroll-loops")
#pragma GCC target("avx2")
const int N = 1e6 + 10, MOD = 998244353;
int timer = 1,pref[N],n,m,used[N];
vector<int> g[N],ord;
bool ok = 1;
void dfs(int v){
used[v] = 1;
for(int to:g[v]){
if(used[to] == 1){
ok = false;
}
if(!used[to]){
dfs(to);
}
}
used[v] = 2;
ord.push_back(v);
}
bool can(int len){
assert(ok == 1);
for(int i = 1;i <= len; i++){
if(i - m >= 0){
g[i - m].push_back(i);
}
if(i - n >= 0){
g[i].push_back(i - n);
}
}
for(int i = 0;i <= len;i++){
if(!used[i]){
dfs(i);
}
}
reverse(ord.begin(),ord.end());
for(auto i:ord){
pref[i] = timer++;
}
timer = 1;
ord.clear();
for(int i = 0;i <= len;i++){
g[i].clear();
}
for(int i = 0;i <= len;i++){
used[i] = 0;
}
bool ans = ok;
ok = 1;
return ans;
}
void test(){
cin >> n >> m;
int l = n + m - gcd(n,m) - 1;
can(l);
cout << l << '\n';
for(int i = 1;i <= l;i++){
cout << pref[i] - pref[i - 1] << ' ';
}
cout << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++)
{
test();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Ok |
2 |
Correct |
6 ms |
27228 KB |
Ok |
3 |
Correct |
6 ms |
27316 KB |
Ok |
4 |
Correct |
5 ms |
27228 KB |
Ok |
5 |
Correct |
6 ms |
27224 KB |
Ok |
6 |
Correct |
6 ms |
27228 KB |
Ok |
7 |
Correct |
6 ms |
27316 KB |
Ok |
8 |
Correct |
6 ms |
27228 KB |
Ok |
9 |
Correct |
5 ms |
27228 KB |
Ok |
10 |
Correct |
6 ms |
27256 KB |
Ok |
11 |
Correct |
6 ms |
27224 KB |
Ok |
12 |
Correct |
6 ms |
27308 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
27228 KB |
Ok |
2 |
Correct |
6 ms |
27224 KB |
Ok |
3 |
Correct |
6 ms |
27228 KB |
Ok |
4 |
Correct |
5 ms |
27244 KB |
Ok |
5 |
Correct |
6 ms |
27228 KB |
Ok |
6 |
Correct |
8 ms |
27228 KB |
Ok |
7 |
Correct |
12 ms |
28212 KB |
Ok |
8 |
Correct |
10 ms |
27484 KB |
Ok |
9 |
Correct |
12 ms |
28284 KB |
Ok |
10 |
Correct |
10 ms |
27740 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
27228 KB |
Ok |
2 |
Correct |
5 ms |
27228 KB |
Ok |
3 |
Correct |
5 ms |
27312 KB |
Ok |
4 |
Correct |
6 ms |
27264 KB |
Ok |
5 |
Correct |
5 ms |
27228 KB |
Ok |
6 |
Correct |
6 ms |
27228 KB |
Ok |
7 |
Correct |
6 ms |
27228 KB |
Ok |
8 |
Correct |
6 ms |
27224 KB |
Ok |
9 |
Correct |
6 ms |
27312 KB |
Ok |
10 |
Correct |
6 ms |
27228 KB |
Ok |
11 |
Correct |
6 ms |
27228 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
27228 KB |
Ok |
2 |
Correct |
6 ms |
27224 KB |
Ok |
3 |
Correct |
5 ms |
27228 KB |
Ok |
4 |
Correct |
6 ms |
27228 KB |
Ok |
5 |
Correct |
6 ms |
27228 KB |
Ok |
6 |
Correct |
64 ms |
41256 KB |
Ok |
7 |
Correct |
57 ms |
40640 KB |
Ok |
8 |
Correct |
116 ms |
43680 KB |
Ok |
9 |
Correct |
86 ms |
41412 KB |
Ok |
10 |
Correct |
51 ms |
36812 KB |
Ok |
11 |
Correct |
83 ms |
44740 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Ok |
2 |
Correct |
6 ms |
27228 KB |
Ok |
3 |
Correct |
6 ms |
27316 KB |
Ok |
4 |
Correct |
5 ms |
27228 KB |
Ok |
5 |
Correct |
6 ms |
27224 KB |
Ok |
6 |
Correct |
6 ms |
27228 KB |
Ok |
7 |
Correct |
6 ms |
27316 KB |
Ok |
8 |
Correct |
6 ms |
27228 KB |
Ok |
9 |
Correct |
5 ms |
27228 KB |
Ok |
10 |
Correct |
6 ms |
27256 KB |
Ok |
11 |
Correct |
6 ms |
27224 KB |
Ok |
12 |
Correct |
6 ms |
27308 KB |
Ok |
13 |
Correct |
6 ms |
27228 KB |
Ok |
14 |
Correct |
5 ms |
27228 KB |
Ok |
15 |
Correct |
5 ms |
27312 KB |
Ok |
16 |
Correct |
6 ms |
27264 KB |
Ok |
17 |
Correct |
5 ms |
27228 KB |
Ok |
18 |
Correct |
6 ms |
27228 KB |
Ok |
19 |
Correct |
6 ms |
27228 KB |
Ok |
20 |
Correct |
6 ms |
27224 KB |
Ok |
21 |
Correct |
6 ms |
27312 KB |
Ok |
22 |
Correct |
6 ms |
27228 KB |
Ok |
23 |
Correct |
6 ms |
27228 KB |
Ok |
24 |
Correct |
7 ms |
27228 KB |
Ok |
25 |
Correct |
6 ms |
27484 KB |
Ok |
26 |
Correct |
7 ms |
27224 KB |
Ok |
27 |
Correct |
7 ms |
27484 KB |
Ok |
28 |
Correct |
6 ms |
27228 KB |
Ok |
29 |
Correct |
6 ms |
27228 KB |
Ok |
30 |
Correct |
7 ms |
27228 KB |
Ok |
31 |
Correct |
7 ms |
27484 KB |
Ok |
32 |
Correct |
7 ms |
27224 KB |
Ok |
33 |
Correct |
8 ms |
27228 KB |
Ok |
34 |
Correct |
8 ms |
27484 KB |
Ok |
35 |
Correct |
8 ms |
27524 KB |
Ok |
36 |
Correct |
9 ms |
27484 KB |
Ok |
37 |
Correct |
8 ms |
27484 KB |
Ok |
38 |
Correct |
8 ms |
27484 KB |
Ok |
39 |
Correct |
8 ms |
27484 KB |
Ok |
40 |
Correct |
8 ms |
27484 KB |
Ok |
41 |
Correct |
8 ms |
27484 KB |
Ok |
42 |
Correct |
8 ms |
27484 KB |
Ok |
43 |
Correct |
8 ms |
27484 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Ok |
2 |
Correct |
6 ms |
27228 KB |
Ok |
3 |
Correct |
6 ms |
27316 KB |
Ok |
4 |
Correct |
5 ms |
27228 KB |
Ok |
5 |
Correct |
6 ms |
27224 KB |
Ok |
6 |
Correct |
6 ms |
27228 KB |
Ok |
7 |
Correct |
6 ms |
27316 KB |
Ok |
8 |
Correct |
6 ms |
27228 KB |
Ok |
9 |
Correct |
5 ms |
27228 KB |
Ok |
10 |
Correct |
6 ms |
27256 KB |
Ok |
11 |
Correct |
6 ms |
27224 KB |
Ok |
12 |
Correct |
6 ms |
27308 KB |
Ok |
13 |
Correct |
6 ms |
27228 KB |
Ok |
14 |
Correct |
6 ms |
27224 KB |
Ok |
15 |
Correct |
6 ms |
27228 KB |
Ok |
16 |
Correct |
5 ms |
27244 KB |
Ok |
17 |
Correct |
6 ms |
27228 KB |
Ok |
18 |
Correct |
8 ms |
27228 KB |
Ok |
19 |
Correct |
12 ms |
28212 KB |
Ok |
20 |
Correct |
10 ms |
27484 KB |
Ok |
21 |
Correct |
12 ms |
28284 KB |
Ok |
22 |
Correct |
10 ms |
27740 KB |
Ok |
23 |
Correct |
6 ms |
27228 KB |
Ok |
24 |
Correct |
5 ms |
27228 KB |
Ok |
25 |
Correct |
5 ms |
27312 KB |
Ok |
26 |
Correct |
6 ms |
27264 KB |
Ok |
27 |
Correct |
5 ms |
27228 KB |
Ok |
28 |
Correct |
6 ms |
27228 KB |
Ok |
29 |
Correct |
6 ms |
27228 KB |
Ok |
30 |
Correct |
6 ms |
27224 KB |
Ok |
31 |
Correct |
6 ms |
27312 KB |
Ok |
32 |
Correct |
6 ms |
27228 KB |
Ok |
33 |
Correct |
6 ms |
27228 KB |
Ok |
34 |
Correct |
7 ms |
27228 KB |
Ok |
35 |
Correct |
6 ms |
27484 KB |
Ok |
36 |
Correct |
7 ms |
27224 KB |
Ok |
37 |
Correct |
7 ms |
27484 KB |
Ok |
38 |
Correct |
6 ms |
27228 KB |
Ok |
39 |
Correct |
6 ms |
27228 KB |
Ok |
40 |
Correct |
7 ms |
27228 KB |
Ok |
41 |
Correct |
7 ms |
27484 KB |
Ok |
42 |
Correct |
7 ms |
27224 KB |
Ok |
43 |
Correct |
8 ms |
27228 KB |
Ok |
44 |
Correct |
8 ms |
27484 KB |
Ok |
45 |
Correct |
8 ms |
27524 KB |
Ok |
46 |
Correct |
9 ms |
27484 KB |
Ok |
47 |
Correct |
8 ms |
27484 KB |
Ok |
48 |
Correct |
8 ms |
27484 KB |
Ok |
49 |
Correct |
8 ms |
27484 KB |
Ok |
50 |
Correct |
8 ms |
27484 KB |
Ok |
51 |
Correct |
8 ms |
27484 KB |
Ok |
52 |
Correct |
8 ms |
27484 KB |
Ok |
53 |
Correct |
8 ms |
27484 KB |
Ok |
54 |
Correct |
47 ms |
32680 KB |
Ok |
55 |
Correct |
54 ms |
32972 KB |
Ok |
56 |
Correct |
52 ms |
32980 KB |
Ok |
57 |
Correct |
41 ms |
32060 KB |
Ok |
58 |
Correct |
51 ms |
32768 KB |
Ok |
59 |
Correct |
55 ms |
32464 KB |
Ok |
60 |
Correct |
45 ms |
31940 KB |
Ok |
61 |
Correct |
44 ms |
32212 KB |
Ok |
62 |
Correct |
69 ms |
33284 KB |
Ok |
63 |
Correct |
47 ms |
32204 KB |
Ok |
64 |
Correct |
66 ms |
32856 KB |
Ok |
65 |
Correct |
53 ms |
32740 KB |
Ok |
66 |
Correct |
46 ms |
32468 KB |
Ok |
67 |
Correct |
42 ms |
32152 KB |
Ok |
68 |
Correct |
51 ms |
32756 KB |
Ok |
69 |
Correct |
102 ms |
40016 KB |
Ok |
70 |
Correct |
101 ms |
39992 KB |
Ok |
71 |
Correct |
93 ms |
38344 KB |
Ok |
72 |
Correct |
94 ms |
39876 KB |
Ok |
73 |
Correct |
97 ms |
38688 KB |
Ok |
74 |
Correct |
99 ms |
39452 KB |
Ok |
75 |
Correct |
96 ms |
39548 KB |
Ok |
76 |
Correct |
102 ms |
39708 KB |
Ok |
77 |
Correct |
91 ms |
38924 KB |
Ok |
78 |
Correct |
106 ms |
39668 KB |
Ok |
79 |
Correct |
107 ms |
39608 KB |
Ok |
80 |
Correct |
93 ms |
38624 KB |
Ok |
81 |
Correct |
92 ms |
39880 KB |
Ok |
82 |
Correct |
92 ms |
39312 KB |
Ok |
83 |
Correct |
92 ms |
39880 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Ok |
2 |
Correct |
6 ms |
27228 KB |
Ok |
3 |
Correct |
6 ms |
27316 KB |
Ok |
4 |
Correct |
5 ms |
27228 KB |
Ok |
5 |
Correct |
6 ms |
27224 KB |
Ok |
6 |
Correct |
6 ms |
27228 KB |
Ok |
7 |
Correct |
6 ms |
27316 KB |
Ok |
8 |
Correct |
6 ms |
27228 KB |
Ok |
9 |
Correct |
5 ms |
27228 KB |
Ok |
10 |
Correct |
6 ms |
27256 KB |
Ok |
11 |
Correct |
6 ms |
27224 KB |
Ok |
12 |
Correct |
6 ms |
27308 KB |
Ok |
13 |
Correct |
6 ms |
27228 KB |
Ok |
14 |
Correct |
6 ms |
27224 KB |
Ok |
15 |
Correct |
6 ms |
27228 KB |
Ok |
16 |
Correct |
5 ms |
27244 KB |
Ok |
17 |
Correct |
6 ms |
27228 KB |
Ok |
18 |
Correct |
8 ms |
27228 KB |
Ok |
19 |
Correct |
12 ms |
28212 KB |
Ok |
20 |
Correct |
10 ms |
27484 KB |
Ok |
21 |
Correct |
12 ms |
28284 KB |
Ok |
22 |
Correct |
10 ms |
27740 KB |
Ok |
23 |
Correct |
6 ms |
27228 KB |
Ok |
24 |
Correct |
5 ms |
27228 KB |
Ok |
25 |
Correct |
5 ms |
27312 KB |
Ok |
26 |
Correct |
6 ms |
27264 KB |
Ok |
27 |
Correct |
5 ms |
27228 KB |
Ok |
28 |
Correct |
6 ms |
27228 KB |
Ok |
29 |
Correct |
6 ms |
27228 KB |
Ok |
30 |
Correct |
6 ms |
27224 KB |
Ok |
31 |
Correct |
6 ms |
27312 KB |
Ok |
32 |
Correct |
6 ms |
27228 KB |
Ok |
33 |
Correct |
6 ms |
27228 KB |
Ok |
34 |
Correct |
6 ms |
27228 KB |
Ok |
35 |
Correct |
6 ms |
27224 KB |
Ok |
36 |
Correct |
5 ms |
27228 KB |
Ok |
37 |
Correct |
6 ms |
27228 KB |
Ok |
38 |
Correct |
6 ms |
27228 KB |
Ok |
39 |
Correct |
64 ms |
41256 KB |
Ok |
40 |
Correct |
57 ms |
40640 KB |
Ok |
41 |
Correct |
116 ms |
43680 KB |
Ok |
42 |
Correct |
86 ms |
41412 KB |
Ok |
43 |
Correct |
51 ms |
36812 KB |
Ok |
44 |
Correct |
83 ms |
44740 KB |
Ok |
45 |
Correct |
7 ms |
27228 KB |
Ok |
46 |
Correct |
6 ms |
27484 KB |
Ok |
47 |
Correct |
7 ms |
27224 KB |
Ok |
48 |
Correct |
7 ms |
27484 KB |
Ok |
49 |
Correct |
6 ms |
27228 KB |
Ok |
50 |
Correct |
6 ms |
27228 KB |
Ok |
51 |
Correct |
7 ms |
27228 KB |
Ok |
52 |
Correct |
7 ms |
27484 KB |
Ok |
53 |
Correct |
7 ms |
27224 KB |
Ok |
54 |
Correct |
8 ms |
27228 KB |
Ok |
55 |
Correct |
8 ms |
27484 KB |
Ok |
56 |
Correct |
8 ms |
27524 KB |
Ok |
57 |
Correct |
9 ms |
27484 KB |
Ok |
58 |
Correct |
8 ms |
27484 KB |
Ok |
59 |
Correct |
8 ms |
27484 KB |
Ok |
60 |
Correct |
8 ms |
27484 KB |
Ok |
61 |
Correct |
8 ms |
27484 KB |
Ok |
62 |
Correct |
8 ms |
27484 KB |
Ok |
63 |
Correct |
8 ms |
27484 KB |
Ok |
64 |
Correct |
8 ms |
27484 KB |
Ok |
65 |
Correct |
47 ms |
32680 KB |
Ok |
66 |
Correct |
54 ms |
32972 KB |
Ok |
67 |
Correct |
52 ms |
32980 KB |
Ok |
68 |
Correct |
41 ms |
32060 KB |
Ok |
69 |
Correct |
51 ms |
32768 KB |
Ok |
70 |
Correct |
55 ms |
32464 KB |
Ok |
71 |
Correct |
45 ms |
31940 KB |
Ok |
72 |
Correct |
44 ms |
32212 KB |
Ok |
73 |
Correct |
69 ms |
33284 KB |
Ok |
74 |
Correct |
47 ms |
32204 KB |
Ok |
75 |
Correct |
66 ms |
32856 KB |
Ok |
76 |
Correct |
53 ms |
32740 KB |
Ok |
77 |
Correct |
46 ms |
32468 KB |
Ok |
78 |
Correct |
42 ms |
32152 KB |
Ok |
79 |
Correct |
51 ms |
32756 KB |
Ok |
80 |
Correct |
102 ms |
40016 KB |
Ok |
81 |
Correct |
101 ms |
39992 KB |
Ok |
82 |
Correct |
93 ms |
38344 KB |
Ok |
83 |
Correct |
94 ms |
39876 KB |
Ok |
84 |
Correct |
97 ms |
38688 KB |
Ok |
85 |
Correct |
99 ms |
39452 KB |
Ok |
86 |
Correct |
96 ms |
39548 KB |
Ok |
87 |
Correct |
102 ms |
39708 KB |
Ok |
88 |
Correct |
91 ms |
38924 KB |
Ok |
89 |
Correct |
106 ms |
39668 KB |
Ok |
90 |
Correct |
107 ms |
39608 KB |
Ok |
91 |
Correct |
93 ms |
38624 KB |
Ok |
92 |
Correct |
92 ms |
39880 KB |
Ok |
93 |
Correct |
92 ms |
39312 KB |
Ok |
94 |
Correct |
92 ms |
39880 KB |
Ok |
95 |
Correct |
123 ms |
41336 KB |
Ok |
96 |
Correct |
201 ms |
48204 KB |
Ok |
97 |
Correct |
164 ms |
44932 KB |
Ok |
98 |
Correct |
122 ms |
43972 KB |
Ok |
99 |
Correct |
146 ms |
44192 KB |
Ok |
100 |
Correct |
146 ms |
44180 KB |
Ok |
101 |
Correct |
155 ms |
46192 KB |
Ok |
102 |
Correct |
141 ms |
44744 KB |
Ok |
103 |
Correct |
146 ms |
45804 KB |
Ok |
104 |
Correct |
170 ms |
47124 KB |
Ok |
105 |
Correct |
162 ms |
47808 KB |
Ok |
106 |
Correct |
156 ms |
46948 KB |
Ok |
107 |
Correct |
160 ms |
46788 KB |
Ok |
108 |
Correct |
180 ms |
47980 KB |
Ok |
109 |
Correct |
160 ms |
48320 KB |
Ok |
110 |
Correct |
722 ms |
81604 KB |
Ok |
111 |
Correct |
878 ms |
82364 KB |
Ok |
112 |
Correct |
907 ms |
78428 KB |
Ok |
113 |
Correct |
766 ms |
81260 KB |
Ok |
114 |
Correct |
916 ms |
77844 KB |
Ok |
115 |
Correct |
935 ms |
82664 KB |
Ok |
116 |
Correct |
945 ms |
82068 KB |
Ok |
117 |
Correct |
883 ms |
82368 KB |
Ok |
118 |
Correct |
833 ms |
77132 KB |
Ok |
119 |
Correct |
845 ms |
81328 KB |
Ok |
120 |
Correct |
877 ms |
82380 KB |
Ok |
121 |
Correct |
832 ms |
79976 KB |
Ok |
122 |
Correct |
835 ms |
82208 KB |
Ok |
123 |
Correct |
782 ms |
80332 KB |
Ok |
124 |
Correct |
807 ms |
78184 KB |
Ok |
125 |
Correct |
277 ms |
65568 KB |
Ok |