#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
int t;
bool OK=true;
int M=0;
vector <int> v[400001];
int mas[400001];
int fix[400001],nmas[1000001];
void go (int u,int col){
if (!OK) return ;
fix[u]=col;
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (fix[node]==col){
OK=false;
return ;
}
if (!OK) return ;
if (fix[node]==0) go(node,col);
}
}
inline bool check (int sz){
for (int i=0;i<=sz;i++){
if (i+n<=sz){
v[i].pb(i+n);
}
if (i+m<=sz){
v[i+m].pb(i);
}
}
OK=true;
for (int i=0;i<=sz;i++){
if (fix[i]==0){
go(i,i+1);
}
}
for (int i=0;i<=sz;i++){
fix[i]=0;
v[i].clear();
}
return OK;
}
void top_sort (int u){
fix[u]=1;
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (fix[node]==0) top_sort(node);
}
mas[u]=++M;
}
inline void solve (int sz){
for (int i=0;i<=sz;i++){
if (i+n<=sz){
v[i].pb(i+n);
}
if (i+m<=sz){
v[i+m].pb(i);
}
}
OK=true;
for (int i=0;i<=sz;i++){
if (fix[i]==0){
top_sort(i);
}
}
for (int i=0;i<=sz;i++){
nmas[i]=mas[i]-mas[i-1];
}
for (int i=0;i<=sz;i++){
fix[i]=0;
v[i].clear();
}
}
main () {
ios::sync_with_stdio(false);
cin>>t;
while (t--){
cin>>n>>m;
int b=0,e=n+m,mid,ans=0;
while (b<=e){
mid= b + e >> 1;
if (check(mid)){
ans=mid;
b=mid+1;
}
else{
e=mid-1;
}
}
M=0;
if (ans>0) solve(ans);
cout<<ans<<endl;
for (int i=1;i<=ans;i++){
cout<<nmas[i]<<" ";
}
cout<<endl;
}
return 0;
}
/*
1
2 4
_ _ _ _
| \ | | (_) | |
| \| | _ ___ | | __ ___ ___ _ __ __ _
| . ` | | | / __| | |/ / / __| / _ \ | '_ \ / _` |
| |\ | | | | (__ | < \__ \ | (_) | | | | | | (_| |
|_| \_| |_| \___| |_|\_\ |___/ \___/ |_| |_| \__,_|
*/
Compilation message
sequence.cpp: In function 'void go(int, int)':
sequence.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[u].size();i++){
~^~~~~~~~~~~~
sequence.cpp: In function 'void top_sort(int)':
sequence.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[u].size();i++){
~^~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:87:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
sequence.cpp: In function 'int main()':
sequence.cpp:94:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid= b + e >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9844 KB |
Ok |
3 |
Correct |
10 ms |
9900 KB |
Ok |
4 |
Correct |
9 ms |
9900 KB |
Ok |
5 |
Correct |
10 ms |
9900 KB |
Ok |
6 |
Correct |
10 ms |
9900 KB |
Ok |
7 |
Correct |
9 ms |
9900 KB |
Ok |
8 |
Correct |
10 ms |
9900 KB |
Ok |
9 |
Correct |
10 ms |
9932 KB |
Ok |
10 |
Correct |
9 ms |
9932 KB |
Ok |
11 |
Correct |
10 ms |
9992 KB |
Ok |
12 |
Correct |
12 ms |
9992 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9992 KB |
Ok |
2 |
Correct |
10 ms |
9992 KB |
Ok |
3 |
Correct |
9 ms |
9992 KB |
Ok |
4 |
Correct |
11 ms |
9992 KB |
Ok |
5 |
Correct |
9 ms |
9992 KB |
Ok |
6 |
Correct |
15 ms |
10180 KB |
Ok |
7 |
Correct |
37 ms |
10936 KB |
Ok |
8 |
Correct |
23 ms |
10936 KB |
Ok |
9 |
Correct |
42 ms |
11108 KB |
Ok |
10 |
Correct |
30 ms |
11108 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11108 KB |
Ok |
2 |
Correct |
11 ms |
11108 KB |
Ok |
3 |
Correct |
11 ms |
11108 KB |
Ok |
4 |
Correct |
11 ms |
11108 KB |
Ok |
5 |
Correct |
11 ms |
11108 KB |
Ok |
6 |
Correct |
11 ms |
11108 KB |
Ok |
7 |
Correct |
11 ms |
11108 KB |
Ok |
8 |
Correct |
11 ms |
11108 KB |
Ok |
9 |
Correct |
11 ms |
11108 KB |
Ok |
10 |
Correct |
10 ms |
11108 KB |
Ok |
11 |
Correct |
11 ms |
11108 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11108 KB |
Ok |
2 |
Correct |
11 ms |
11108 KB |
Ok |
3 |
Correct |
10 ms |
11108 KB |
Ok |
4 |
Correct |
10 ms |
11108 KB |
Ok |
5 |
Correct |
11 ms |
11108 KB |
Ok |
6 |
Correct |
413 ms |
25316 KB |
Ok |
7 |
Correct |
361 ms |
26792 KB |
Ok |
8 |
Correct |
704 ms |
29828 KB |
Ok |
9 |
Correct |
484 ms |
29828 KB |
Ok |
10 |
Correct |
270 ms |
29828 KB |
Ok |
11 |
Correct |
432 ms |
29828 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9844 KB |
Ok |
3 |
Correct |
10 ms |
9900 KB |
Ok |
4 |
Correct |
9 ms |
9900 KB |
Ok |
5 |
Correct |
10 ms |
9900 KB |
Ok |
6 |
Correct |
10 ms |
9900 KB |
Ok |
7 |
Correct |
9 ms |
9900 KB |
Ok |
8 |
Correct |
10 ms |
9900 KB |
Ok |
9 |
Correct |
10 ms |
9932 KB |
Ok |
10 |
Correct |
9 ms |
9932 KB |
Ok |
11 |
Correct |
10 ms |
9992 KB |
Ok |
12 |
Correct |
12 ms |
9992 KB |
Ok |
13 |
Correct |
9 ms |
11108 KB |
Ok |
14 |
Correct |
11 ms |
11108 KB |
Ok |
15 |
Correct |
11 ms |
11108 KB |
Ok |
16 |
Correct |
11 ms |
11108 KB |
Ok |
17 |
Correct |
11 ms |
11108 KB |
Ok |
18 |
Correct |
11 ms |
11108 KB |
Ok |
19 |
Correct |
11 ms |
11108 KB |
Ok |
20 |
Correct |
11 ms |
11108 KB |
Ok |
21 |
Correct |
11 ms |
11108 KB |
Ok |
22 |
Correct |
10 ms |
11108 KB |
Ok |
23 |
Correct |
11 ms |
11108 KB |
Ok |
24 |
Correct |
16 ms |
29828 KB |
Ok |
25 |
Correct |
15 ms |
29828 KB |
Ok |
26 |
Correct |
15 ms |
29828 KB |
Ok |
27 |
Correct |
17 ms |
29828 KB |
Ok |
28 |
Correct |
14 ms |
29828 KB |
Ok |
29 |
Correct |
14 ms |
29828 KB |
Ok |
30 |
Correct |
14 ms |
29828 KB |
Ok |
31 |
Correct |
14 ms |
29828 KB |
Ok |
32 |
Correct |
14 ms |
29828 KB |
Ok |
33 |
Correct |
13 ms |
29828 KB |
Ok |
34 |
Correct |
23 ms |
29828 KB |
Ok |
35 |
Correct |
24 ms |
29828 KB |
Ok |
36 |
Correct |
24 ms |
29828 KB |
Ok |
37 |
Correct |
24 ms |
29828 KB |
Ok |
38 |
Correct |
24 ms |
29828 KB |
Ok |
39 |
Correct |
23 ms |
29828 KB |
Ok |
40 |
Correct |
25 ms |
29828 KB |
Ok |
41 |
Correct |
23 ms |
29828 KB |
Ok |
42 |
Correct |
25 ms |
29828 KB |
Ok |
43 |
Correct |
24 ms |
29828 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9844 KB |
Ok |
3 |
Correct |
10 ms |
9900 KB |
Ok |
4 |
Correct |
9 ms |
9900 KB |
Ok |
5 |
Correct |
10 ms |
9900 KB |
Ok |
6 |
Correct |
10 ms |
9900 KB |
Ok |
7 |
Correct |
9 ms |
9900 KB |
Ok |
8 |
Correct |
10 ms |
9900 KB |
Ok |
9 |
Correct |
10 ms |
9932 KB |
Ok |
10 |
Correct |
9 ms |
9932 KB |
Ok |
11 |
Correct |
10 ms |
9992 KB |
Ok |
12 |
Correct |
12 ms |
9992 KB |
Ok |
13 |
Correct |
9 ms |
9992 KB |
Ok |
14 |
Correct |
10 ms |
9992 KB |
Ok |
15 |
Correct |
9 ms |
9992 KB |
Ok |
16 |
Correct |
11 ms |
9992 KB |
Ok |
17 |
Correct |
9 ms |
9992 KB |
Ok |
18 |
Correct |
15 ms |
10180 KB |
Ok |
19 |
Correct |
37 ms |
10936 KB |
Ok |
20 |
Correct |
23 ms |
10936 KB |
Ok |
21 |
Correct |
42 ms |
11108 KB |
Ok |
22 |
Correct |
30 ms |
11108 KB |
Ok |
23 |
Correct |
9 ms |
11108 KB |
Ok |
24 |
Correct |
11 ms |
11108 KB |
Ok |
25 |
Correct |
11 ms |
11108 KB |
Ok |
26 |
Correct |
11 ms |
11108 KB |
Ok |
27 |
Correct |
11 ms |
11108 KB |
Ok |
28 |
Correct |
11 ms |
11108 KB |
Ok |
29 |
Correct |
11 ms |
11108 KB |
Ok |
30 |
Correct |
11 ms |
11108 KB |
Ok |
31 |
Correct |
11 ms |
11108 KB |
Ok |
32 |
Correct |
10 ms |
11108 KB |
Ok |
33 |
Correct |
11 ms |
11108 KB |
Ok |
34 |
Correct |
16 ms |
29828 KB |
Ok |
35 |
Correct |
15 ms |
29828 KB |
Ok |
36 |
Correct |
15 ms |
29828 KB |
Ok |
37 |
Correct |
17 ms |
29828 KB |
Ok |
38 |
Correct |
14 ms |
29828 KB |
Ok |
39 |
Correct |
14 ms |
29828 KB |
Ok |
40 |
Correct |
14 ms |
29828 KB |
Ok |
41 |
Correct |
14 ms |
29828 KB |
Ok |
42 |
Correct |
14 ms |
29828 KB |
Ok |
43 |
Correct |
13 ms |
29828 KB |
Ok |
44 |
Correct |
23 ms |
29828 KB |
Ok |
45 |
Correct |
24 ms |
29828 KB |
Ok |
46 |
Correct |
24 ms |
29828 KB |
Ok |
47 |
Correct |
24 ms |
29828 KB |
Ok |
48 |
Correct |
24 ms |
29828 KB |
Ok |
49 |
Correct |
23 ms |
29828 KB |
Ok |
50 |
Correct |
25 ms |
29828 KB |
Ok |
51 |
Correct |
23 ms |
29828 KB |
Ok |
52 |
Correct |
25 ms |
29828 KB |
Ok |
53 |
Correct |
24 ms |
29828 KB |
Ok |
54 |
Correct |
338 ms |
29828 KB |
Ok |
55 |
Correct |
382 ms |
29828 KB |
Ok |
56 |
Correct |
398 ms |
29828 KB |
Ok |
57 |
Correct |
230 ms |
29828 KB |
Ok |
58 |
Correct |
278 ms |
29828 KB |
Ok |
59 |
Correct |
224 ms |
29828 KB |
Ok |
60 |
Correct |
207 ms |
29828 KB |
Ok |
61 |
Correct |
215 ms |
29828 KB |
Ok |
62 |
Correct |
294 ms |
29828 KB |
Ok |
63 |
Correct |
263 ms |
29828 KB |
Ok |
64 |
Correct |
349 ms |
29828 KB |
Ok |
65 |
Correct |
269 ms |
29828 KB |
Ok |
66 |
Correct |
251 ms |
29828 KB |
Ok |
67 |
Correct |
245 ms |
29828 KB |
Ok |
68 |
Correct |
262 ms |
29828 KB |
Ok |
69 |
Correct |
1010 ms |
29828 KB |
Ok |
70 |
Correct |
1149 ms |
29828 KB |
Ok |
71 |
Correct |
927 ms |
29828 KB |
Ok |
72 |
Correct |
931 ms |
29828 KB |
Ok |
73 |
Correct |
930 ms |
29828 KB |
Ok |
74 |
Correct |
763 ms |
29828 KB |
Ok |
75 |
Correct |
861 ms |
29828 KB |
Ok |
76 |
Correct |
1143 ms |
29828 KB |
Ok |
77 |
Correct |
799 ms |
29828 KB |
Ok |
78 |
Correct |
1016 ms |
29828 KB |
Ok |
79 |
Correct |
1035 ms |
29828 KB |
Ok |
80 |
Correct |
929 ms |
29828 KB |
Ok |
81 |
Correct |
982 ms |
29828 KB |
Ok |
82 |
Correct |
789 ms |
29828 KB |
Ok |
83 |
Correct |
784 ms |
29828 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9844 KB |
Ok |
3 |
Correct |
10 ms |
9900 KB |
Ok |
4 |
Correct |
9 ms |
9900 KB |
Ok |
5 |
Correct |
10 ms |
9900 KB |
Ok |
6 |
Correct |
10 ms |
9900 KB |
Ok |
7 |
Correct |
9 ms |
9900 KB |
Ok |
8 |
Correct |
10 ms |
9900 KB |
Ok |
9 |
Correct |
10 ms |
9932 KB |
Ok |
10 |
Correct |
9 ms |
9932 KB |
Ok |
11 |
Correct |
10 ms |
9992 KB |
Ok |
12 |
Correct |
12 ms |
9992 KB |
Ok |
13 |
Correct |
9 ms |
9992 KB |
Ok |
14 |
Correct |
10 ms |
9992 KB |
Ok |
15 |
Correct |
9 ms |
9992 KB |
Ok |
16 |
Correct |
11 ms |
9992 KB |
Ok |
17 |
Correct |
9 ms |
9992 KB |
Ok |
18 |
Correct |
15 ms |
10180 KB |
Ok |
19 |
Correct |
37 ms |
10936 KB |
Ok |
20 |
Correct |
23 ms |
10936 KB |
Ok |
21 |
Correct |
42 ms |
11108 KB |
Ok |
22 |
Correct |
30 ms |
11108 KB |
Ok |
23 |
Correct |
9 ms |
11108 KB |
Ok |
24 |
Correct |
11 ms |
11108 KB |
Ok |
25 |
Correct |
11 ms |
11108 KB |
Ok |
26 |
Correct |
11 ms |
11108 KB |
Ok |
27 |
Correct |
11 ms |
11108 KB |
Ok |
28 |
Correct |
11 ms |
11108 KB |
Ok |
29 |
Correct |
11 ms |
11108 KB |
Ok |
30 |
Correct |
11 ms |
11108 KB |
Ok |
31 |
Correct |
11 ms |
11108 KB |
Ok |
32 |
Correct |
10 ms |
11108 KB |
Ok |
33 |
Correct |
11 ms |
11108 KB |
Ok |
34 |
Correct |
10 ms |
11108 KB |
Ok |
35 |
Correct |
11 ms |
11108 KB |
Ok |
36 |
Correct |
10 ms |
11108 KB |
Ok |
37 |
Correct |
10 ms |
11108 KB |
Ok |
38 |
Correct |
11 ms |
11108 KB |
Ok |
39 |
Correct |
413 ms |
25316 KB |
Ok |
40 |
Correct |
361 ms |
26792 KB |
Ok |
41 |
Correct |
704 ms |
29828 KB |
Ok |
42 |
Correct |
484 ms |
29828 KB |
Ok |
43 |
Correct |
270 ms |
29828 KB |
Ok |
44 |
Correct |
432 ms |
29828 KB |
Ok |
45 |
Correct |
16 ms |
29828 KB |
Ok |
46 |
Correct |
15 ms |
29828 KB |
Ok |
47 |
Correct |
15 ms |
29828 KB |
Ok |
48 |
Correct |
17 ms |
29828 KB |
Ok |
49 |
Correct |
14 ms |
29828 KB |
Ok |
50 |
Correct |
14 ms |
29828 KB |
Ok |
51 |
Correct |
14 ms |
29828 KB |
Ok |
52 |
Correct |
14 ms |
29828 KB |
Ok |
53 |
Correct |
14 ms |
29828 KB |
Ok |
54 |
Correct |
13 ms |
29828 KB |
Ok |
55 |
Correct |
23 ms |
29828 KB |
Ok |
56 |
Correct |
24 ms |
29828 KB |
Ok |
57 |
Correct |
24 ms |
29828 KB |
Ok |
58 |
Correct |
24 ms |
29828 KB |
Ok |
59 |
Correct |
24 ms |
29828 KB |
Ok |
60 |
Correct |
23 ms |
29828 KB |
Ok |
61 |
Correct |
25 ms |
29828 KB |
Ok |
62 |
Correct |
23 ms |
29828 KB |
Ok |
63 |
Correct |
25 ms |
29828 KB |
Ok |
64 |
Correct |
24 ms |
29828 KB |
Ok |
65 |
Correct |
338 ms |
29828 KB |
Ok |
66 |
Correct |
382 ms |
29828 KB |
Ok |
67 |
Correct |
398 ms |
29828 KB |
Ok |
68 |
Correct |
230 ms |
29828 KB |
Ok |
69 |
Correct |
278 ms |
29828 KB |
Ok |
70 |
Correct |
224 ms |
29828 KB |
Ok |
71 |
Correct |
207 ms |
29828 KB |
Ok |
72 |
Correct |
215 ms |
29828 KB |
Ok |
73 |
Correct |
294 ms |
29828 KB |
Ok |
74 |
Correct |
263 ms |
29828 KB |
Ok |
75 |
Correct |
349 ms |
29828 KB |
Ok |
76 |
Correct |
269 ms |
29828 KB |
Ok |
77 |
Correct |
251 ms |
29828 KB |
Ok |
78 |
Correct |
245 ms |
29828 KB |
Ok |
79 |
Correct |
262 ms |
29828 KB |
Ok |
80 |
Correct |
1010 ms |
29828 KB |
Ok |
81 |
Correct |
1149 ms |
29828 KB |
Ok |
82 |
Correct |
927 ms |
29828 KB |
Ok |
83 |
Correct |
931 ms |
29828 KB |
Ok |
84 |
Correct |
930 ms |
29828 KB |
Ok |
85 |
Correct |
763 ms |
29828 KB |
Ok |
86 |
Correct |
861 ms |
29828 KB |
Ok |
87 |
Correct |
1143 ms |
29828 KB |
Ok |
88 |
Correct |
799 ms |
29828 KB |
Ok |
89 |
Correct |
1016 ms |
29828 KB |
Ok |
90 |
Correct |
1035 ms |
29828 KB |
Ok |
91 |
Correct |
929 ms |
29828 KB |
Ok |
92 |
Correct |
982 ms |
29828 KB |
Ok |
93 |
Correct |
789 ms |
29828 KB |
Ok |
94 |
Correct |
784 ms |
29828 KB |
Ok |
95 |
Correct |
918 ms |
29828 KB |
Ok |
96 |
Correct |
1331 ms |
31312 KB |
Ok |
97 |
Correct |
1414 ms |
31312 KB |
Ok |
98 |
Correct |
835 ms |
31312 KB |
Ok |
99 |
Correct |
1066 ms |
31312 KB |
Ok |
100 |
Correct |
1329 ms |
31312 KB |
Ok |
101 |
Correct |
1393 ms |
31312 KB |
Ok |
102 |
Correct |
1394 ms |
31312 KB |
Ok |
103 |
Correct |
1075 ms |
31312 KB |
Ok |
104 |
Execution timed out |
2017 ms |
31312 KB |
Time limit exceeded |
105 |
Halted |
0 ms |
0 KB |
- |