#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll N=2e6+5;
const ll MOD=1e9+7;
const ll INF=(1LL<<60);
const ld pi=acos(-1);
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define ALL(_a) _a.begin(),_a.end()
#define SZ(_a) (ll)_a.size()
ll dg[N],p[N],n,m,t,x;
bool ck(ll L){
memset(dg,0,sizeof(dg));
REP(i,L+1){
if(i>=n)++dg[i-n];
if(i+m<=L)++dg[i+m];
}
queue<ll> que;
REP(i,L+1)if(dg[i]==0)que.push(i),p[i]=0;
ll ptr=0;
while(SZ(que)){
x=que.front();que.pop();
p[x]=++ptr;
if(x>=n){
if(--dg[x-n]==0)que.push(x-n);
}
if(x+m<=L){
if(--dg[x+m]==0)que.push(x+m);
}
}
REP(i,L+1)if(dg[i])return 0;
return 1;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>t;
while(t--){
cin>>n>>m;
ll l=n+m-__gcd(n,m)-1;
ck(l);
cout<<l<<"\n";
if(l==0)continue;
if(l)REP1(i,l)cout<<p[i]-p[i-1]<<" \n"[i==l];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
15980 KB |
Ok |
2 |
Correct |
28 ms |
15980 KB |
Ok |
3 |
Correct |
28 ms |
15980 KB |
Ok |
4 |
Correct |
27 ms |
15980 KB |
Ok |
5 |
Correct |
27 ms |
15980 KB |
Ok |
6 |
Correct |
28 ms |
15980 KB |
Ok |
7 |
Correct |
28 ms |
15980 KB |
Ok |
8 |
Correct |
30 ms |
15980 KB |
Ok |
9 |
Correct |
27 ms |
15980 KB |
Ok |
10 |
Correct |
27 ms |
15980 KB |
Ok |
11 |
Correct |
27 ms |
15980 KB |
Ok |
12 |
Correct |
27 ms |
15980 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
15980 KB |
Ok |
2 |
Correct |
27 ms |
15980 KB |
Ok |
3 |
Correct |
26 ms |
15980 KB |
Ok |
4 |
Correct |
27 ms |
15980 KB |
Ok |
5 |
Correct |
26 ms |
16260 KB |
Ok |
6 |
Correct |
28 ms |
16108 KB |
Ok |
7 |
Correct |
35 ms |
16364 KB |
Ok |
8 |
Correct |
31 ms |
16236 KB |
Ok |
9 |
Correct |
39 ms |
16480 KB |
Ok |
10 |
Correct |
33 ms |
16236 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
15980 KB |
Ok |
2 |
Correct |
29 ms |
16060 KB |
Ok |
3 |
Correct |
27 ms |
16060 KB |
Ok |
4 |
Correct |
28 ms |
15980 KB |
Ok |
5 |
Correct |
28 ms |
15980 KB |
Ok |
6 |
Correct |
28 ms |
15980 KB |
Ok |
7 |
Correct |
28 ms |
15980 KB |
Ok |
8 |
Correct |
27 ms |
15980 KB |
Ok |
9 |
Correct |
28 ms |
15980 KB |
Ok |
10 |
Correct |
28 ms |
15980 KB |
Ok |
11 |
Correct |
28 ms |
15980 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
16012 KB |
Ok |
2 |
Correct |
27 ms |
15980 KB |
Ok |
3 |
Correct |
28 ms |
15980 KB |
Ok |
4 |
Correct |
29 ms |
16108 KB |
Ok |
5 |
Correct |
29 ms |
15980 KB |
Ok |
6 |
Correct |
102 ms |
20076 KB |
Ok |
7 |
Correct |
97 ms |
19692 KB |
Ok |
8 |
Correct |
157 ms |
21612 KB |
Ok |
9 |
Correct |
125 ms |
22124 KB |
Ok |
10 |
Correct |
83 ms |
18540 KB |
Ok |
11 |
Correct |
128 ms |
21228 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
15980 KB |
Ok |
2 |
Correct |
28 ms |
15980 KB |
Ok |
3 |
Correct |
28 ms |
15980 KB |
Ok |
4 |
Correct |
27 ms |
15980 KB |
Ok |
5 |
Correct |
27 ms |
15980 KB |
Ok |
6 |
Correct |
28 ms |
15980 KB |
Ok |
7 |
Correct |
28 ms |
15980 KB |
Ok |
8 |
Correct |
30 ms |
15980 KB |
Ok |
9 |
Correct |
27 ms |
15980 KB |
Ok |
10 |
Correct |
27 ms |
15980 KB |
Ok |
11 |
Correct |
27 ms |
15980 KB |
Ok |
12 |
Correct |
27 ms |
15980 KB |
Ok |
13 |
Correct |
12 ms |
15980 KB |
Ok |
14 |
Correct |
29 ms |
16060 KB |
Ok |
15 |
Correct |
27 ms |
16060 KB |
Ok |
16 |
Correct |
28 ms |
15980 KB |
Ok |
17 |
Correct |
28 ms |
15980 KB |
Ok |
18 |
Correct |
28 ms |
15980 KB |
Ok |
19 |
Correct |
28 ms |
15980 KB |
Ok |
20 |
Correct |
27 ms |
15980 KB |
Ok |
21 |
Correct |
28 ms |
15980 KB |
Ok |
22 |
Correct |
28 ms |
15980 KB |
Ok |
23 |
Correct |
28 ms |
15980 KB |
Ok |
24 |
Correct |
29 ms |
16108 KB |
Ok |
25 |
Correct |
30 ms |
16108 KB |
Ok |
26 |
Correct |
30 ms |
16108 KB |
Ok |
27 |
Correct |
30 ms |
16108 KB |
Ok |
28 |
Correct |
31 ms |
16108 KB |
Ok |
29 |
Correct |
33 ms |
16108 KB |
Ok |
30 |
Correct |
29 ms |
16108 KB |
Ok |
31 |
Correct |
31 ms |
16108 KB |
Ok |
32 |
Correct |
31 ms |
16108 KB |
Ok |
33 |
Correct |
29 ms |
16108 KB |
Ok |
34 |
Correct |
32 ms |
16108 KB |
Ok |
35 |
Correct |
31 ms |
16236 KB |
Ok |
36 |
Correct |
32 ms |
16108 KB |
Ok |
37 |
Correct |
32 ms |
16236 KB |
Ok |
38 |
Correct |
31 ms |
16236 KB |
Ok |
39 |
Correct |
31 ms |
16108 KB |
Ok |
40 |
Correct |
34 ms |
16236 KB |
Ok |
41 |
Correct |
31 ms |
16236 KB |
Ok |
42 |
Correct |
31 ms |
16108 KB |
Ok |
43 |
Correct |
31 ms |
16236 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
15980 KB |
Ok |
2 |
Correct |
28 ms |
15980 KB |
Ok |
3 |
Correct |
28 ms |
15980 KB |
Ok |
4 |
Correct |
27 ms |
15980 KB |
Ok |
5 |
Correct |
27 ms |
15980 KB |
Ok |
6 |
Correct |
28 ms |
15980 KB |
Ok |
7 |
Correct |
28 ms |
15980 KB |
Ok |
8 |
Correct |
30 ms |
15980 KB |
Ok |
9 |
Correct |
27 ms |
15980 KB |
Ok |
10 |
Correct |
27 ms |
15980 KB |
Ok |
11 |
Correct |
27 ms |
15980 KB |
Ok |
12 |
Correct |
27 ms |
15980 KB |
Ok |
13 |
Correct |
26 ms |
15980 KB |
Ok |
14 |
Correct |
27 ms |
15980 KB |
Ok |
15 |
Correct |
26 ms |
15980 KB |
Ok |
16 |
Correct |
27 ms |
15980 KB |
Ok |
17 |
Correct |
26 ms |
16260 KB |
Ok |
18 |
Correct |
28 ms |
16108 KB |
Ok |
19 |
Correct |
35 ms |
16364 KB |
Ok |
20 |
Correct |
31 ms |
16236 KB |
Ok |
21 |
Correct |
39 ms |
16480 KB |
Ok |
22 |
Correct |
33 ms |
16236 KB |
Ok |
23 |
Correct |
12 ms |
15980 KB |
Ok |
24 |
Correct |
29 ms |
16060 KB |
Ok |
25 |
Correct |
27 ms |
16060 KB |
Ok |
26 |
Correct |
28 ms |
15980 KB |
Ok |
27 |
Correct |
28 ms |
15980 KB |
Ok |
28 |
Correct |
28 ms |
15980 KB |
Ok |
29 |
Correct |
28 ms |
15980 KB |
Ok |
30 |
Correct |
27 ms |
15980 KB |
Ok |
31 |
Correct |
28 ms |
15980 KB |
Ok |
32 |
Correct |
28 ms |
15980 KB |
Ok |
33 |
Correct |
28 ms |
15980 KB |
Ok |
34 |
Correct |
29 ms |
16108 KB |
Ok |
35 |
Correct |
30 ms |
16108 KB |
Ok |
36 |
Correct |
30 ms |
16108 KB |
Ok |
37 |
Correct |
30 ms |
16108 KB |
Ok |
38 |
Correct |
31 ms |
16108 KB |
Ok |
39 |
Correct |
33 ms |
16108 KB |
Ok |
40 |
Correct |
29 ms |
16108 KB |
Ok |
41 |
Correct |
31 ms |
16108 KB |
Ok |
42 |
Correct |
31 ms |
16108 KB |
Ok |
43 |
Correct |
29 ms |
16108 KB |
Ok |
44 |
Correct |
32 ms |
16108 KB |
Ok |
45 |
Correct |
31 ms |
16236 KB |
Ok |
46 |
Correct |
32 ms |
16108 KB |
Ok |
47 |
Correct |
32 ms |
16236 KB |
Ok |
48 |
Correct |
31 ms |
16236 KB |
Ok |
49 |
Correct |
31 ms |
16108 KB |
Ok |
50 |
Correct |
34 ms |
16236 KB |
Ok |
51 |
Correct |
31 ms |
16236 KB |
Ok |
52 |
Correct |
31 ms |
16108 KB |
Ok |
53 |
Correct |
31 ms |
16236 KB |
Ok |
54 |
Correct |
100 ms |
18328 KB |
Ok |
55 |
Correct |
98 ms |
18452 KB |
Ok |
56 |
Correct |
95 ms |
18532 KB |
Ok |
57 |
Correct |
81 ms |
18076 KB |
Ok |
58 |
Correct |
93 ms |
18556 KB |
Ok |
59 |
Correct |
104 ms |
18296 KB |
Ok |
60 |
Correct |
82 ms |
18028 KB |
Ok |
61 |
Correct |
81 ms |
18108 KB |
Ok |
62 |
Correct |
98 ms |
18540 KB |
Ok |
63 |
Correct |
88 ms |
18420 KB |
Ok |
64 |
Correct |
96 ms |
18432 KB |
Ok |
65 |
Correct |
94 ms |
18396 KB |
Ok |
66 |
Correct |
89 ms |
18152 KB |
Ok |
67 |
Correct |
81 ms |
18000 KB |
Ok |
68 |
Correct |
92 ms |
18416 KB |
Ok |
69 |
Correct |
133 ms |
22124 KB |
Ok |
70 |
Correct |
135 ms |
23404 KB |
Ok |
71 |
Correct |
137 ms |
21288 KB |
Ok |
72 |
Correct |
135 ms |
22508 KB |
Ok |
73 |
Correct |
133 ms |
21868 KB |
Ok |
74 |
Correct |
131 ms |
20844 KB |
Ok |
75 |
Correct |
135 ms |
20972 KB |
Ok |
76 |
Correct |
137 ms |
23148 KB |
Ok |
77 |
Correct |
132 ms |
20588 KB |
Ok |
78 |
Correct |
136 ms |
22764 KB |
Ok |
79 |
Correct |
134 ms |
22252 KB |
Ok |
80 |
Correct |
132 ms |
21868 KB |
Ok |
81 |
Correct |
141 ms |
22508 KB |
Ok |
82 |
Correct |
133 ms |
21996 KB |
Ok |
83 |
Correct |
131 ms |
21100 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
15980 KB |
Ok |
2 |
Correct |
28 ms |
15980 KB |
Ok |
3 |
Correct |
28 ms |
15980 KB |
Ok |
4 |
Correct |
27 ms |
15980 KB |
Ok |
5 |
Correct |
27 ms |
15980 KB |
Ok |
6 |
Correct |
28 ms |
15980 KB |
Ok |
7 |
Correct |
28 ms |
15980 KB |
Ok |
8 |
Correct |
30 ms |
15980 KB |
Ok |
9 |
Correct |
27 ms |
15980 KB |
Ok |
10 |
Correct |
27 ms |
15980 KB |
Ok |
11 |
Correct |
27 ms |
15980 KB |
Ok |
12 |
Correct |
27 ms |
15980 KB |
Ok |
13 |
Correct |
26 ms |
15980 KB |
Ok |
14 |
Correct |
27 ms |
15980 KB |
Ok |
15 |
Correct |
26 ms |
15980 KB |
Ok |
16 |
Correct |
27 ms |
15980 KB |
Ok |
17 |
Correct |
26 ms |
16260 KB |
Ok |
18 |
Correct |
28 ms |
16108 KB |
Ok |
19 |
Correct |
35 ms |
16364 KB |
Ok |
20 |
Correct |
31 ms |
16236 KB |
Ok |
21 |
Correct |
39 ms |
16480 KB |
Ok |
22 |
Correct |
33 ms |
16236 KB |
Ok |
23 |
Correct |
12 ms |
15980 KB |
Ok |
24 |
Correct |
29 ms |
16060 KB |
Ok |
25 |
Correct |
27 ms |
16060 KB |
Ok |
26 |
Correct |
28 ms |
15980 KB |
Ok |
27 |
Correct |
28 ms |
15980 KB |
Ok |
28 |
Correct |
28 ms |
15980 KB |
Ok |
29 |
Correct |
28 ms |
15980 KB |
Ok |
30 |
Correct |
27 ms |
15980 KB |
Ok |
31 |
Correct |
28 ms |
15980 KB |
Ok |
32 |
Correct |
28 ms |
15980 KB |
Ok |
33 |
Correct |
28 ms |
15980 KB |
Ok |
34 |
Correct |
29 ms |
16012 KB |
Ok |
35 |
Correct |
27 ms |
15980 KB |
Ok |
36 |
Correct |
28 ms |
15980 KB |
Ok |
37 |
Correct |
29 ms |
16108 KB |
Ok |
38 |
Correct |
29 ms |
15980 KB |
Ok |
39 |
Correct |
102 ms |
20076 KB |
Ok |
40 |
Correct |
97 ms |
19692 KB |
Ok |
41 |
Correct |
157 ms |
21612 KB |
Ok |
42 |
Correct |
125 ms |
22124 KB |
Ok |
43 |
Correct |
83 ms |
18540 KB |
Ok |
44 |
Correct |
128 ms |
21228 KB |
Ok |
45 |
Correct |
29 ms |
16108 KB |
Ok |
46 |
Correct |
30 ms |
16108 KB |
Ok |
47 |
Correct |
30 ms |
16108 KB |
Ok |
48 |
Correct |
30 ms |
16108 KB |
Ok |
49 |
Correct |
31 ms |
16108 KB |
Ok |
50 |
Correct |
33 ms |
16108 KB |
Ok |
51 |
Correct |
29 ms |
16108 KB |
Ok |
52 |
Correct |
31 ms |
16108 KB |
Ok |
53 |
Correct |
31 ms |
16108 KB |
Ok |
54 |
Correct |
29 ms |
16108 KB |
Ok |
55 |
Correct |
32 ms |
16108 KB |
Ok |
56 |
Correct |
31 ms |
16236 KB |
Ok |
57 |
Correct |
32 ms |
16108 KB |
Ok |
58 |
Correct |
32 ms |
16236 KB |
Ok |
59 |
Correct |
31 ms |
16236 KB |
Ok |
60 |
Correct |
31 ms |
16108 KB |
Ok |
61 |
Correct |
34 ms |
16236 KB |
Ok |
62 |
Correct |
31 ms |
16236 KB |
Ok |
63 |
Correct |
31 ms |
16108 KB |
Ok |
64 |
Correct |
31 ms |
16236 KB |
Ok |
65 |
Correct |
100 ms |
18328 KB |
Ok |
66 |
Correct |
98 ms |
18452 KB |
Ok |
67 |
Correct |
95 ms |
18532 KB |
Ok |
68 |
Correct |
81 ms |
18076 KB |
Ok |
69 |
Correct |
93 ms |
18556 KB |
Ok |
70 |
Correct |
104 ms |
18296 KB |
Ok |
71 |
Correct |
82 ms |
18028 KB |
Ok |
72 |
Correct |
81 ms |
18108 KB |
Ok |
73 |
Correct |
98 ms |
18540 KB |
Ok |
74 |
Correct |
88 ms |
18420 KB |
Ok |
75 |
Correct |
96 ms |
18432 KB |
Ok |
76 |
Correct |
94 ms |
18396 KB |
Ok |
77 |
Correct |
89 ms |
18152 KB |
Ok |
78 |
Correct |
81 ms |
18000 KB |
Ok |
79 |
Correct |
92 ms |
18416 KB |
Ok |
80 |
Correct |
133 ms |
22124 KB |
Ok |
81 |
Correct |
135 ms |
23404 KB |
Ok |
82 |
Correct |
137 ms |
21288 KB |
Ok |
83 |
Correct |
135 ms |
22508 KB |
Ok |
84 |
Correct |
133 ms |
21868 KB |
Ok |
85 |
Correct |
131 ms |
20844 KB |
Ok |
86 |
Correct |
135 ms |
20972 KB |
Ok |
87 |
Correct |
137 ms |
23148 KB |
Ok |
88 |
Correct |
132 ms |
20588 KB |
Ok |
89 |
Correct |
136 ms |
22764 KB |
Ok |
90 |
Correct |
134 ms |
22252 KB |
Ok |
91 |
Correct |
132 ms |
21868 KB |
Ok |
92 |
Correct |
141 ms |
22508 KB |
Ok |
93 |
Correct |
133 ms |
21996 KB |
Ok |
94 |
Correct |
131 ms |
21100 KB |
Ok |
95 |
Correct |
184 ms |
22340 KB |
Ok |
96 |
Correct |
248 ms |
24848 KB |
Ok |
97 |
Correct |
267 ms |
23744 KB |
Ok |
98 |
Correct |
202 ms |
23208 KB |
Ok |
99 |
Correct |
231 ms |
22972 KB |
Ok |
100 |
Correct |
226 ms |
22772 KB |
Ok |
101 |
Correct |
242 ms |
23856 KB |
Ok |
102 |
Correct |
223 ms |
22848 KB |
Ok |
103 |
Correct |
219 ms |
23312 KB |
Ok |
104 |
Correct |
258 ms |
25016 KB |
Ok |
105 |
Correct |
245 ms |
23640 KB |
Ok |
106 |
Correct |
211 ms |
23628 KB |
Ok |
107 |
Correct |
239 ms |
23852 KB |
Ok |
108 |
Correct |
272 ms |
24152 KB |
Ok |
109 |
Correct |
235 ms |
23992 KB |
Ok |
110 |
Correct |
480 ms |
37192 KB |
Ok |
111 |
Correct |
550 ms |
47060 KB |
Ok |
112 |
Correct |
524 ms |
39276 KB |
Ok |
113 |
Correct |
512 ms |
43280 KB |
Ok |
114 |
Correct |
522 ms |
44652 KB |
Ok |
115 |
Correct |
553 ms |
44012 KB |
Ok |
116 |
Correct |
561 ms |
43796 KB |
Ok |
117 |
Correct |
529 ms |
44584 KB |
Ok |
118 |
Correct |
530 ms |
40192 KB |
Ok |
119 |
Correct |
548 ms |
45676 KB |
Ok |
120 |
Correct |
514 ms |
40300 KB |
Ok |
121 |
Correct |
508 ms |
39148 KB |
Ok |
122 |
Correct |
512 ms |
42496 KB |
Ok |
123 |
Correct |
552 ms |
47084 KB |
Ok |
124 |
Correct |
503 ms |
36164 KB |
Ok |
125 |
Correct |
396 ms |
29292 KB |
Ok |