#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC opimize(-O3)
//#pragma GCC opimize(Ofast)
//#pragma GCC opimize(unroll-loops)
//#pragma GCC target("avx,avx2,popcnt,sse,sse2,sse3,sse4,abm,tune=native")
#define m_p make_pair
#define vec vector
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef long double ld;
typedef pair<int,int> pii;
const int N=4e5+1;
int ok=1;
int used[N];
vec<int>g[N];
int pref[N];
vec<int>ord;
void dfs(int v){
used[v]=1;
for(auto &z : g[v]){
if(used[z]==1){
ok=0;
}
else if(!used[z]){
dfs(z);
}
}
used[v]=2;
}
void dfs1(int v){
used[v]=1;
for(auto &z : g[v]){
if(!used[z]){
dfs1(z);
}
}
ord.pb(v);
}
int getlen(int n,int m){
return n+m-__gcd(n,m)-1;
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int q=10;
scanf("%d",&q);
// cin>>q;
// ofstream cout("out.txt");
while(q--){
int n,m;
// n=199999;m=200000;
ord.clear();
scanf("%d%d",&n,&m);
int wow=getlen(n,m);
auto check=[&](int mid){
for(int i=0;i<=mid;i++) g[i].clear(),used[i]=0;
for(int i=0;i<=mid;i++){
if(i>=n){
g[i-n].pb(i);
}
if(i>=m){
g[i].pb(i-m);
}
}
ok=1;
for(int i=0;i<=mid;i++){
if(!used[i]){
dfs(i);
}
}
return ok;
};
int l=getlen(n,m)+1,r=l;
while(l!=r){
int tm=(l+r)>>1;
if(check(tm)){
l=tm+1;
}
else{
r=tm;
}
}
l--;
assert(l==wow);
for(int i=0;i<=l;i++) g[i].clear(),used[i]=0;
for(int i=0;i<=l;i++){
if(i>=n){
g[i-n].pb(i);
}
if(i>=m){
g[i].pb(i-m);
}
}
for(int i=0;i<=l;i++){
if(!used[i]){
dfs1(i);
}
}
// reverse(all(ord));
int i=1;
for(auto &z : ord) pref[z]=i++;
// cout<<l<<'\n';
printf("%d%c",l,'\n');
// cout<<l<<'\n';
for(int i=1;i<=l;i++){
// cout<<pref[i]-pref[i-1]<<' ';
printf("%d%c",pref[i]-pref[i-1],' ');
}
printf("%c",'\n');
// cout<<'\n';
}
return 0;
}
/*
5 1
1 1 2
1 3 5
3 2 3 1
2 1
3 0 3 1
*/
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
sequence.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9732 KB |
Ok |
2 |
Correct |
8 ms |
9684 KB |
Ok |
3 |
Correct |
6 ms |
9684 KB |
Ok |
4 |
Correct |
7 ms |
9736 KB |
Ok |
5 |
Correct |
5 ms |
9684 KB |
Ok |
6 |
Correct |
6 ms |
9732 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
5 ms |
9684 KB |
Ok |
10 |
Correct |
8 ms |
9672 KB |
Ok |
11 |
Correct |
9 ms |
9684 KB |
Ok |
12 |
Correct |
6 ms |
9684 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Ok |
2 |
Correct |
5 ms |
9684 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
7 ms |
9744 KB |
Ok |
5 |
Correct |
6 ms |
9684 KB |
Ok |
6 |
Correct |
11 ms |
9860 KB |
Ok |
7 |
Correct |
18 ms |
10756 KB |
Ok |
8 |
Correct |
11 ms |
10204 KB |
Ok |
9 |
Correct |
17 ms |
10836 KB |
Ok |
10 |
Correct |
12 ms |
10372 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9732 KB |
Ok |
2 |
Correct |
6 ms |
9620 KB |
Ok |
3 |
Correct |
5 ms |
9732 KB |
Ok |
4 |
Correct |
5 ms |
9684 KB |
Ok |
5 |
Correct |
6 ms |
9684 KB |
Ok |
6 |
Correct |
6 ms |
9732 KB |
Ok |
7 |
Correct |
5 ms |
9720 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
6 ms |
9684 KB |
Ok |
10 |
Correct |
6 ms |
9684 KB |
Ok |
11 |
Correct |
6 ms |
9684 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Ok |
2 |
Correct |
5 ms |
9684 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
6 ms |
9684 KB |
Ok |
5 |
Correct |
6 ms |
9684 KB |
Ok |
6 |
Correct |
122 ms |
23196 KB |
Ok |
7 |
Correct |
103 ms |
29500 KB |
Ok |
8 |
Correct |
191 ms |
32320 KB |
Ok |
9 |
Correct |
143 ms |
29452 KB |
Ok |
10 |
Correct |
82 ms |
20120 KB |
Ok |
11 |
Correct |
144 ms |
26184 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9732 KB |
Ok |
2 |
Correct |
8 ms |
9684 KB |
Ok |
3 |
Correct |
6 ms |
9684 KB |
Ok |
4 |
Correct |
7 ms |
9736 KB |
Ok |
5 |
Correct |
5 ms |
9684 KB |
Ok |
6 |
Correct |
6 ms |
9732 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
5 ms |
9684 KB |
Ok |
10 |
Correct |
8 ms |
9672 KB |
Ok |
11 |
Correct |
9 ms |
9684 KB |
Ok |
12 |
Correct |
6 ms |
9684 KB |
Ok |
13 |
Correct |
5 ms |
9732 KB |
Ok |
14 |
Correct |
6 ms |
9620 KB |
Ok |
15 |
Correct |
5 ms |
9732 KB |
Ok |
16 |
Correct |
5 ms |
9684 KB |
Ok |
17 |
Correct |
6 ms |
9684 KB |
Ok |
18 |
Correct |
6 ms |
9732 KB |
Ok |
19 |
Correct |
5 ms |
9720 KB |
Ok |
20 |
Correct |
6 ms |
9684 KB |
Ok |
21 |
Correct |
6 ms |
9684 KB |
Ok |
22 |
Correct |
6 ms |
9684 KB |
Ok |
23 |
Correct |
6 ms |
9684 KB |
Ok |
24 |
Correct |
10 ms |
9844 KB |
Ok |
25 |
Correct |
7 ms |
9848 KB |
Ok |
26 |
Correct |
8 ms |
9860 KB |
Ok |
27 |
Correct |
7 ms |
9812 KB |
Ok |
28 |
Correct |
7 ms |
9840 KB |
Ok |
29 |
Correct |
8 ms |
9840 KB |
Ok |
30 |
Correct |
7 ms |
9812 KB |
Ok |
31 |
Correct |
7 ms |
9812 KB |
Ok |
32 |
Correct |
7 ms |
9820 KB |
Ok |
33 |
Correct |
8 ms |
9940 KB |
Ok |
34 |
Correct |
11 ms |
10068 KB |
Ok |
35 |
Correct |
10 ms |
10136 KB |
Ok |
36 |
Correct |
14 ms |
10068 KB |
Ok |
37 |
Correct |
12 ms |
10116 KB |
Ok |
38 |
Correct |
10 ms |
10164 KB |
Ok |
39 |
Correct |
12 ms |
10116 KB |
Ok |
40 |
Correct |
12 ms |
10196 KB |
Ok |
41 |
Correct |
9 ms |
10068 KB |
Ok |
42 |
Correct |
10 ms |
9988 KB |
Ok |
43 |
Correct |
9 ms |
10196 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9732 KB |
Ok |
2 |
Correct |
8 ms |
9684 KB |
Ok |
3 |
Correct |
6 ms |
9684 KB |
Ok |
4 |
Correct |
7 ms |
9736 KB |
Ok |
5 |
Correct |
5 ms |
9684 KB |
Ok |
6 |
Correct |
6 ms |
9732 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
5 ms |
9684 KB |
Ok |
10 |
Correct |
8 ms |
9672 KB |
Ok |
11 |
Correct |
9 ms |
9684 KB |
Ok |
12 |
Correct |
6 ms |
9684 KB |
Ok |
13 |
Correct |
5 ms |
9684 KB |
Ok |
14 |
Correct |
5 ms |
9684 KB |
Ok |
15 |
Correct |
5 ms |
9684 KB |
Ok |
16 |
Correct |
7 ms |
9744 KB |
Ok |
17 |
Correct |
6 ms |
9684 KB |
Ok |
18 |
Correct |
11 ms |
9860 KB |
Ok |
19 |
Correct |
18 ms |
10756 KB |
Ok |
20 |
Correct |
11 ms |
10204 KB |
Ok |
21 |
Correct |
17 ms |
10836 KB |
Ok |
22 |
Correct |
12 ms |
10372 KB |
Ok |
23 |
Correct |
5 ms |
9732 KB |
Ok |
24 |
Correct |
6 ms |
9620 KB |
Ok |
25 |
Correct |
5 ms |
9732 KB |
Ok |
26 |
Correct |
5 ms |
9684 KB |
Ok |
27 |
Correct |
6 ms |
9684 KB |
Ok |
28 |
Correct |
6 ms |
9732 KB |
Ok |
29 |
Correct |
5 ms |
9720 KB |
Ok |
30 |
Correct |
6 ms |
9684 KB |
Ok |
31 |
Correct |
6 ms |
9684 KB |
Ok |
32 |
Correct |
6 ms |
9684 KB |
Ok |
33 |
Correct |
6 ms |
9684 KB |
Ok |
34 |
Correct |
10 ms |
9844 KB |
Ok |
35 |
Correct |
7 ms |
9848 KB |
Ok |
36 |
Correct |
8 ms |
9860 KB |
Ok |
37 |
Correct |
7 ms |
9812 KB |
Ok |
38 |
Correct |
7 ms |
9840 KB |
Ok |
39 |
Correct |
8 ms |
9840 KB |
Ok |
40 |
Correct |
7 ms |
9812 KB |
Ok |
41 |
Correct |
7 ms |
9812 KB |
Ok |
42 |
Correct |
7 ms |
9820 KB |
Ok |
43 |
Correct |
8 ms |
9940 KB |
Ok |
44 |
Correct |
11 ms |
10068 KB |
Ok |
45 |
Correct |
10 ms |
10136 KB |
Ok |
46 |
Correct |
14 ms |
10068 KB |
Ok |
47 |
Correct |
12 ms |
10116 KB |
Ok |
48 |
Correct |
10 ms |
10164 KB |
Ok |
49 |
Correct |
12 ms |
10116 KB |
Ok |
50 |
Correct |
12 ms |
10196 KB |
Ok |
51 |
Correct |
9 ms |
10068 KB |
Ok |
52 |
Correct |
10 ms |
9988 KB |
Ok |
53 |
Correct |
9 ms |
10196 KB |
Ok |
54 |
Correct |
92 ms |
15288 KB |
Ok |
55 |
Correct |
95 ms |
15612 KB |
Ok |
56 |
Correct |
92 ms |
15692 KB |
Ok |
57 |
Correct |
72 ms |
14620 KB |
Ok |
58 |
Correct |
84 ms |
15024 KB |
Ok |
59 |
Correct |
80 ms |
14708 KB |
Ok |
60 |
Correct |
75 ms |
14372 KB |
Ok |
61 |
Correct |
72 ms |
14924 KB |
Ok |
62 |
Correct |
96 ms |
15428 KB |
Ok |
63 |
Correct |
79 ms |
14668 KB |
Ok |
64 |
Correct |
96 ms |
15624 KB |
Ok |
65 |
Correct |
90 ms |
15180 KB |
Ok |
66 |
Correct |
88 ms |
15080 KB |
Ok |
67 |
Correct |
74 ms |
14884 KB |
Ok |
68 |
Correct |
81 ms |
15168 KB |
Ok |
69 |
Correct |
176 ms |
24604 KB |
Ok |
70 |
Correct |
185 ms |
25308 KB |
Ok |
71 |
Correct |
183 ms |
24528 KB |
Ok |
72 |
Correct |
169 ms |
24624 KB |
Ok |
73 |
Correct |
178 ms |
23944 KB |
Ok |
74 |
Correct |
194 ms |
23764 KB |
Ok |
75 |
Correct |
170 ms |
23816 KB |
Ok |
76 |
Correct |
173 ms |
24732 KB |
Ok |
77 |
Correct |
201 ms |
23152 KB |
Ok |
78 |
Correct |
158 ms |
23600 KB |
Ok |
79 |
Correct |
204 ms |
24376 KB |
Ok |
80 |
Correct |
176 ms |
24512 KB |
Ok |
81 |
Correct |
183 ms |
23748 KB |
Ok |
82 |
Correct |
186 ms |
24260 KB |
Ok |
83 |
Correct |
181 ms |
23772 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9732 KB |
Ok |
2 |
Correct |
8 ms |
9684 KB |
Ok |
3 |
Correct |
6 ms |
9684 KB |
Ok |
4 |
Correct |
7 ms |
9736 KB |
Ok |
5 |
Correct |
5 ms |
9684 KB |
Ok |
6 |
Correct |
6 ms |
9732 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
5 ms |
9684 KB |
Ok |
10 |
Correct |
8 ms |
9672 KB |
Ok |
11 |
Correct |
9 ms |
9684 KB |
Ok |
12 |
Correct |
6 ms |
9684 KB |
Ok |
13 |
Correct |
5 ms |
9684 KB |
Ok |
14 |
Correct |
5 ms |
9684 KB |
Ok |
15 |
Correct |
5 ms |
9684 KB |
Ok |
16 |
Correct |
7 ms |
9744 KB |
Ok |
17 |
Correct |
6 ms |
9684 KB |
Ok |
18 |
Correct |
11 ms |
9860 KB |
Ok |
19 |
Correct |
18 ms |
10756 KB |
Ok |
20 |
Correct |
11 ms |
10204 KB |
Ok |
21 |
Correct |
17 ms |
10836 KB |
Ok |
22 |
Correct |
12 ms |
10372 KB |
Ok |
23 |
Correct |
5 ms |
9732 KB |
Ok |
24 |
Correct |
6 ms |
9620 KB |
Ok |
25 |
Correct |
5 ms |
9732 KB |
Ok |
26 |
Correct |
5 ms |
9684 KB |
Ok |
27 |
Correct |
6 ms |
9684 KB |
Ok |
28 |
Correct |
6 ms |
9732 KB |
Ok |
29 |
Correct |
5 ms |
9720 KB |
Ok |
30 |
Correct |
6 ms |
9684 KB |
Ok |
31 |
Correct |
6 ms |
9684 KB |
Ok |
32 |
Correct |
6 ms |
9684 KB |
Ok |
33 |
Correct |
6 ms |
9684 KB |
Ok |
34 |
Correct |
6 ms |
9684 KB |
Ok |
35 |
Correct |
5 ms |
9684 KB |
Ok |
36 |
Correct |
5 ms |
9684 KB |
Ok |
37 |
Correct |
6 ms |
9684 KB |
Ok |
38 |
Correct |
6 ms |
9684 KB |
Ok |
39 |
Correct |
122 ms |
23196 KB |
Ok |
40 |
Correct |
103 ms |
29500 KB |
Ok |
41 |
Correct |
191 ms |
32320 KB |
Ok |
42 |
Correct |
143 ms |
29452 KB |
Ok |
43 |
Correct |
82 ms |
20120 KB |
Ok |
44 |
Correct |
144 ms |
26184 KB |
Ok |
45 |
Correct |
10 ms |
9844 KB |
Ok |
46 |
Correct |
7 ms |
9848 KB |
Ok |
47 |
Correct |
8 ms |
9860 KB |
Ok |
48 |
Correct |
7 ms |
9812 KB |
Ok |
49 |
Correct |
7 ms |
9840 KB |
Ok |
50 |
Correct |
8 ms |
9840 KB |
Ok |
51 |
Correct |
7 ms |
9812 KB |
Ok |
52 |
Correct |
7 ms |
9812 KB |
Ok |
53 |
Correct |
7 ms |
9820 KB |
Ok |
54 |
Correct |
8 ms |
9940 KB |
Ok |
55 |
Correct |
11 ms |
10068 KB |
Ok |
56 |
Correct |
10 ms |
10136 KB |
Ok |
57 |
Correct |
14 ms |
10068 KB |
Ok |
58 |
Correct |
12 ms |
10116 KB |
Ok |
59 |
Correct |
10 ms |
10164 KB |
Ok |
60 |
Correct |
12 ms |
10116 KB |
Ok |
61 |
Correct |
12 ms |
10196 KB |
Ok |
62 |
Correct |
9 ms |
10068 KB |
Ok |
63 |
Correct |
10 ms |
9988 KB |
Ok |
64 |
Correct |
9 ms |
10196 KB |
Ok |
65 |
Correct |
92 ms |
15288 KB |
Ok |
66 |
Correct |
95 ms |
15612 KB |
Ok |
67 |
Correct |
92 ms |
15692 KB |
Ok |
68 |
Correct |
72 ms |
14620 KB |
Ok |
69 |
Correct |
84 ms |
15024 KB |
Ok |
70 |
Correct |
80 ms |
14708 KB |
Ok |
71 |
Correct |
75 ms |
14372 KB |
Ok |
72 |
Correct |
72 ms |
14924 KB |
Ok |
73 |
Correct |
96 ms |
15428 KB |
Ok |
74 |
Correct |
79 ms |
14668 KB |
Ok |
75 |
Correct |
96 ms |
15624 KB |
Ok |
76 |
Correct |
90 ms |
15180 KB |
Ok |
77 |
Correct |
88 ms |
15080 KB |
Ok |
78 |
Correct |
74 ms |
14884 KB |
Ok |
79 |
Correct |
81 ms |
15168 KB |
Ok |
80 |
Correct |
176 ms |
24604 KB |
Ok |
81 |
Correct |
185 ms |
25308 KB |
Ok |
82 |
Correct |
183 ms |
24528 KB |
Ok |
83 |
Correct |
169 ms |
24624 KB |
Ok |
84 |
Correct |
178 ms |
23944 KB |
Ok |
85 |
Correct |
194 ms |
23764 KB |
Ok |
86 |
Correct |
170 ms |
23816 KB |
Ok |
87 |
Correct |
173 ms |
24732 KB |
Ok |
88 |
Correct |
201 ms |
23152 KB |
Ok |
89 |
Correct |
158 ms |
23600 KB |
Ok |
90 |
Correct |
204 ms |
24376 KB |
Ok |
91 |
Correct |
176 ms |
24512 KB |
Ok |
92 |
Correct |
183 ms |
23748 KB |
Ok |
93 |
Correct |
186 ms |
24260 KB |
Ok |
94 |
Correct |
181 ms |
23772 KB |
Ok |
95 |
Correct |
226 ms |
24240 KB |
Ok |
96 |
Correct |
306 ms |
30592 KB |
Ok |
97 |
Correct |
284 ms |
26872 KB |
Ok |
98 |
Correct |
223 ms |
26944 KB |
Ok |
99 |
Correct |
266 ms |
26492 KB |
Ok |
100 |
Correct |
264 ms |
25944 KB |
Ok |
101 |
Correct |
259 ms |
29020 KB |
Ok |
102 |
Correct |
267 ms |
27160 KB |
Ok |
103 |
Correct |
252 ms |
28104 KB |
Ok |
104 |
Correct |
341 ms |
30012 KB |
Ok |
105 |
Correct |
298 ms |
30488 KB |
Ok |
106 |
Correct |
251 ms |
30648 KB |
Ok |
107 |
Correct |
273 ms |
29460 KB |
Ok |
108 |
Correct |
323 ms |
30236 KB |
Ok |
109 |
Correct |
309 ms |
31616 KB |
Ok |
110 |
Correct |
992 ms |
69256 KB |
Ok |
111 |
Correct |
1094 ms |
71428 KB |
Ok |
112 |
Correct |
1073 ms |
67640 KB |
Ok |
113 |
Correct |
1058 ms |
72044 KB |
Ok |
114 |
Correct |
1077 ms |
71788 KB |
Ok |
115 |
Correct |
1101 ms |
69048 KB |
Ok |
116 |
Correct |
1121 ms |
71812 KB |
Ok |
117 |
Correct |
1008 ms |
71092 KB |
Ok |
118 |
Correct |
1163 ms |
71652 KB |
Ok |
119 |
Correct |
1062 ms |
70460 KB |
Ok |
120 |
Correct |
1073 ms |
70236 KB |
Ok |
121 |
Correct |
1173 ms |
70412 KB |
Ok |
122 |
Correct |
1073 ms |
69676 KB |
Ok |
123 |
Correct |
1346 ms |
71856 KB |
Ok |
124 |
Correct |
1032 ms |
65684 KB |
Ok |
125 |
Correct |
516 ms |
55868 KB |
Ok |