#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
int check(int a,int b,int k){
vector<int> s(k+1);
int now=0;
while(1){
s[now]=1;
if(now>=b){
now-=b;
}
else{
now+=a;
}
if(now==0){
return 1;
}
if(now>k||s[now]==1){
return 0;
}
}
}
void solve(){
int a,b;cin>>a>>b;
int l=0,r=a+b+5;
while(r-l>1){
int m=(l+r)>>1;
if(check(a,b,m)){
r=m;
}
else{
l=m;
}
}
cout<<l<<endl;
vector<int> ans(l+1);
vector<int> in(l+1);
for(int i=0;i<=l;i++){
if(i>=a){
in[i-a]++;
}
if(i+b<=l){
in[i+b]++;
}
}
queue<int> q;
for(int i=0;i<=l;i++){
if(in[i]==0){
q.push(i);
}
}
int cnt=1;
while(q.size()){
int p=q.front();
q.pop();
ans[p]=cnt++;
if(p>=a){
in[p-a]--;
if(in[p-a]==0){
q.push(p-a);
}
}
if(p+b<=l){
in[p+b]--;
if(in[p+b]==0){
q.push(p+b);
}
}
}
for(int i=1;i<=l;i++){
cout<<ans[i]-ans[i-1]<<' ';
}
cout<<endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
344 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
0 ms |
344 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
1 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
456 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
2 ms |
348 KB |
Ok |
7 |
Correct |
9 ms |
860 KB |
Ok |
8 |
Correct |
3 ms |
604 KB |
Ok |
9 |
Correct |
7 ms |
940 KB |
Ok |
10 |
Correct |
4 ms |
604 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
456 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
604 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
452 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
456 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
60 ms |
5796 KB |
Ok |
7 |
Correct |
56 ms |
5028 KB |
Ok |
8 |
Correct |
103 ms |
8516 KB |
Ok |
9 |
Correct |
79 ms |
7860 KB |
Ok |
10 |
Correct |
44 ms |
3940 KB |
Ok |
11 |
Correct |
74 ms |
7184 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
344 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
0 ms |
344 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
456 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
1 ms |
604 KB |
Ok |
17 |
Correct |
0 ms |
348 KB |
Ok |
18 |
Correct |
0 ms |
452 KB |
Ok |
19 |
Correct |
0 ms |
348 KB |
Ok |
20 |
Correct |
0 ms |
348 KB |
Ok |
21 |
Correct |
0 ms |
348 KB |
Ok |
22 |
Correct |
0 ms |
348 KB |
Ok |
23 |
Correct |
0 ms |
456 KB |
Ok |
24 |
Correct |
1 ms |
344 KB |
Ok |
25 |
Correct |
2 ms |
348 KB |
Ok |
26 |
Correct |
1 ms |
348 KB |
Ok |
27 |
Correct |
2 ms |
348 KB |
Ok |
28 |
Correct |
1 ms |
348 KB |
Ok |
29 |
Correct |
2 ms |
344 KB |
Ok |
30 |
Correct |
1 ms |
344 KB |
Ok |
31 |
Correct |
2 ms |
452 KB |
Ok |
32 |
Correct |
2 ms |
348 KB |
Ok |
33 |
Correct |
1 ms |
456 KB |
Ok |
34 |
Correct |
3 ms |
604 KB |
Ok |
35 |
Correct |
3 ms |
604 KB |
Ok |
36 |
Correct |
3 ms |
604 KB |
Ok |
37 |
Correct |
3 ms |
600 KB |
Ok |
38 |
Correct |
3 ms |
584 KB |
Ok |
39 |
Correct |
3 ms |
604 KB |
Ok |
40 |
Correct |
3 ms |
600 KB |
Ok |
41 |
Correct |
3 ms |
604 KB |
Ok |
42 |
Correct |
3 ms |
520 KB |
Ok |
43 |
Correct |
3 ms |
600 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
344 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
0 ms |
344 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
1 ms |
348 KB |
Ok |
14 |
Correct |
1 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
456 KB |
Ok |
17 |
Correct |
1 ms |
348 KB |
Ok |
18 |
Correct |
2 ms |
348 KB |
Ok |
19 |
Correct |
9 ms |
860 KB |
Ok |
20 |
Correct |
3 ms |
604 KB |
Ok |
21 |
Correct |
7 ms |
940 KB |
Ok |
22 |
Correct |
4 ms |
604 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
456 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Correct |
1 ms |
604 KB |
Ok |
27 |
Correct |
0 ms |
348 KB |
Ok |
28 |
Correct |
0 ms |
452 KB |
Ok |
29 |
Correct |
0 ms |
348 KB |
Ok |
30 |
Correct |
0 ms |
348 KB |
Ok |
31 |
Correct |
0 ms |
348 KB |
Ok |
32 |
Correct |
0 ms |
348 KB |
Ok |
33 |
Correct |
0 ms |
456 KB |
Ok |
34 |
Correct |
1 ms |
344 KB |
Ok |
35 |
Correct |
2 ms |
348 KB |
Ok |
36 |
Correct |
1 ms |
348 KB |
Ok |
37 |
Correct |
2 ms |
348 KB |
Ok |
38 |
Correct |
1 ms |
348 KB |
Ok |
39 |
Correct |
2 ms |
344 KB |
Ok |
40 |
Correct |
1 ms |
344 KB |
Ok |
41 |
Correct |
2 ms |
452 KB |
Ok |
42 |
Correct |
2 ms |
348 KB |
Ok |
43 |
Correct |
1 ms |
456 KB |
Ok |
44 |
Correct |
3 ms |
604 KB |
Ok |
45 |
Correct |
3 ms |
604 KB |
Ok |
46 |
Correct |
3 ms |
604 KB |
Ok |
47 |
Correct |
3 ms |
600 KB |
Ok |
48 |
Correct |
3 ms |
584 KB |
Ok |
49 |
Correct |
3 ms |
604 KB |
Ok |
50 |
Correct |
3 ms |
600 KB |
Ok |
51 |
Correct |
3 ms |
604 KB |
Ok |
52 |
Correct |
3 ms |
520 KB |
Ok |
53 |
Correct |
3 ms |
600 KB |
Ok |
54 |
Correct |
45 ms |
3716 KB |
Ok |
55 |
Correct |
48 ms |
4344 KB |
Ok |
56 |
Correct |
47 ms |
3788 KB |
Ok |
57 |
Correct |
40 ms |
3408 KB |
Ok |
58 |
Correct |
43 ms |
3684 KB |
Ok |
59 |
Correct |
43 ms |
3600 KB |
Ok |
60 |
Correct |
38 ms |
3420 KB |
Ok |
61 |
Correct |
38 ms |
3380 KB |
Ok |
62 |
Correct |
50 ms |
3908 KB |
Ok |
63 |
Correct |
36 ms |
3404 KB |
Ok |
64 |
Correct |
47 ms |
3736 KB |
Ok |
65 |
Correct |
48 ms |
3832 KB |
Ok |
66 |
Correct |
42 ms |
3692 KB |
Ok |
67 |
Correct |
41 ms |
4100 KB |
Ok |
68 |
Correct |
42 ms |
4104 KB |
Ok |
69 |
Correct |
77 ms |
7956 KB |
Ok |
70 |
Correct |
81 ms |
9352 KB |
Ok |
71 |
Correct |
77 ms |
7252 KB |
Ok |
72 |
Correct |
86 ms |
8364 KB |
Ok |
73 |
Correct |
73 ms |
7796 KB |
Ok |
74 |
Correct |
73 ms |
6796 KB |
Ok |
75 |
Correct |
79 ms |
6004 KB |
Ok |
76 |
Correct |
77 ms |
8124 KB |
Ok |
77 |
Correct |
71 ms |
6268 KB |
Ok |
78 |
Correct |
77 ms |
8580 KB |
Ok |
79 |
Correct |
74 ms |
8304 KB |
Ok |
80 |
Correct |
76 ms |
7060 KB |
Ok |
81 |
Correct |
78 ms |
8628 KB |
Ok |
82 |
Correct |
81 ms |
7076 KB |
Ok |
83 |
Correct |
71 ms |
6888 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
344 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
0 ms |
344 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
1 ms |
348 KB |
Ok |
14 |
Correct |
1 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
456 KB |
Ok |
17 |
Correct |
1 ms |
348 KB |
Ok |
18 |
Correct |
2 ms |
348 KB |
Ok |
19 |
Correct |
9 ms |
860 KB |
Ok |
20 |
Correct |
3 ms |
604 KB |
Ok |
21 |
Correct |
7 ms |
940 KB |
Ok |
22 |
Correct |
4 ms |
604 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
456 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Correct |
1 ms |
604 KB |
Ok |
27 |
Correct |
0 ms |
348 KB |
Ok |
28 |
Correct |
0 ms |
452 KB |
Ok |
29 |
Correct |
0 ms |
348 KB |
Ok |
30 |
Correct |
0 ms |
348 KB |
Ok |
31 |
Correct |
0 ms |
348 KB |
Ok |
32 |
Correct |
0 ms |
348 KB |
Ok |
33 |
Correct |
0 ms |
456 KB |
Ok |
34 |
Correct |
0 ms |
348 KB |
Ok |
35 |
Correct |
0 ms |
348 KB |
Ok |
36 |
Correct |
0 ms |
348 KB |
Ok |
37 |
Correct |
0 ms |
348 KB |
Ok |
38 |
Correct |
1 ms |
348 KB |
Ok |
39 |
Correct |
60 ms |
5796 KB |
Ok |
40 |
Correct |
56 ms |
5028 KB |
Ok |
41 |
Correct |
103 ms |
8516 KB |
Ok |
42 |
Correct |
79 ms |
7860 KB |
Ok |
43 |
Correct |
44 ms |
3940 KB |
Ok |
44 |
Correct |
74 ms |
7184 KB |
Ok |
45 |
Correct |
1 ms |
344 KB |
Ok |
46 |
Correct |
2 ms |
348 KB |
Ok |
47 |
Correct |
1 ms |
348 KB |
Ok |
48 |
Correct |
2 ms |
348 KB |
Ok |
49 |
Correct |
1 ms |
348 KB |
Ok |
50 |
Correct |
2 ms |
344 KB |
Ok |
51 |
Correct |
1 ms |
344 KB |
Ok |
52 |
Correct |
2 ms |
452 KB |
Ok |
53 |
Correct |
2 ms |
348 KB |
Ok |
54 |
Correct |
1 ms |
456 KB |
Ok |
55 |
Correct |
3 ms |
604 KB |
Ok |
56 |
Correct |
3 ms |
604 KB |
Ok |
57 |
Correct |
3 ms |
604 KB |
Ok |
58 |
Correct |
3 ms |
600 KB |
Ok |
59 |
Correct |
3 ms |
584 KB |
Ok |
60 |
Correct |
3 ms |
604 KB |
Ok |
61 |
Correct |
3 ms |
600 KB |
Ok |
62 |
Correct |
3 ms |
604 KB |
Ok |
63 |
Correct |
3 ms |
520 KB |
Ok |
64 |
Correct |
3 ms |
600 KB |
Ok |
65 |
Correct |
45 ms |
3716 KB |
Ok |
66 |
Correct |
48 ms |
4344 KB |
Ok |
67 |
Correct |
47 ms |
3788 KB |
Ok |
68 |
Correct |
40 ms |
3408 KB |
Ok |
69 |
Correct |
43 ms |
3684 KB |
Ok |
70 |
Correct |
43 ms |
3600 KB |
Ok |
71 |
Correct |
38 ms |
3420 KB |
Ok |
72 |
Correct |
38 ms |
3380 KB |
Ok |
73 |
Correct |
50 ms |
3908 KB |
Ok |
74 |
Correct |
36 ms |
3404 KB |
Ok |
75 |
Correct |
47 ms |
3736 KB |
Ok |
76 |
Correct |
48 ms |
3832 KB |
Ok |
77 |
Correct |
42 ms |
3692 KB |
Ok |
78 |
Correct |
41 ms |
4100 KB |
Ok |
79 |
Correct |
42 ms |
4104 KB |
Ok |
80 |
Correct |
77 ms |
7956 KB |
Ok |
81 |
Correct |
81 ms |
9352 KB |
Ok |
82 |
Correct |
77 ms |
7252 KB |
Ok |
83 |
Correct |
86 ms |
8364 KB |
Ok |
84 |
Correct |
73 ms |
7796 KB |
Ok |
85 |
Correct |
73 ms |
6796 KB |
Ok |
86 |
Correct |
79 ms |
6004 KB |
Ok |
87 |
Correct |
77 ms |
8124 KB |
Ok |
88 |
Correct |
71 ms |
6268 KB |
Ok |
89 |
Correct |
77 ms |
8580 KB |
Ok |
90 |
Correct |
74 ms |
8304 KB |
Ok |
91 |
Correct |
76 ms |
7060 KB |
Ok |
92 |
Correct |
78 ms |
8628 KB |
Ok |
93 |
Correct |
81 ms |
7076 KB |
Ok |
94 |
Correct |
71 ms |
6888 KB |
Ok |
95 |
Correct |
112 ms |
8388 KB |
Ok |
96 |
Correct |
156 ms |
13728 KB |
Ok |
97 |
Correct |
154 ms |
12872 KB |
Ok |
98 |
Correct |
120 ms |
9536 KB |
Ok |
99 |
Correct |
138 ms |
11608 KB |
Ok |
100 |
Correct |
139 ms |
10728 KB |
Ok |
101 |
Correct |
142 ms |
11448 KB |
Ok |
102 |
Correct |
143 ms |
11580 KB |
Ok |
103 |
Correct |
134 ms |
11784 KB |
Ok |
104 |
Correct |
164 ms |
12460 KB |
Ok |
105 |
Correct |
149 ms |
15316 KB |
Ok |
106 |
Correct |
130 ms |
10836 KB |
Ok |
107 |
Correct |
146 ms |
11896 KB |
Ok |
108 |
Correct |
156 ms |
14540 KB |
Ok |
109 |
Correct |
136 ms |
13384 KB |
Ok |
110 |
Correct |
294 ms |
27824 KB |
Ok |
111 |
Correct |
312 ms |
37276 KB |
Ok |
112 |
Correct |
295 ms |
29976 KB |
Ok |
113 |
Correct |
297 ms |
33788 KB |
Ok |
114 |
Correct |
306 ms |
33232 KB |
Ok |
115 |
Correct |
299 ms |
31356 KB |
Ok |
116 |
Correct |
312 ms |
32316 KB |
Ok |
117 |
Correct |
340 ms |
31952 KB |
Ok |
118 |
Correct |
296 ms |
30820 KB |
Ok |
119 |
Correct |
319 ms |
36312 KB |
Ok |
120 |
Correct |
314 ms |
30732 KB |
Ok |
121 |
Correct |
290 ms |
29552 KB |
Ok |
122 |
Correct |
300 ms |
29892 KB |
Ok |
123 |
Correct |
344 ms |
37396 KB |
Ok |
124 |
Correct |
292 ms |
24288 KB |
Ok |
125 |
Correct |
304 ms |
16660 KB |
Ok |