#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
int n, m, mul, k, lim;
int arr[2*N], curVal;
bool vis[2*N], possible;
void solve(int pos) {
if (arr[pos] != 0) return;
if (vis[pos]) {
possible = 0;
return;
}
vis[pos] = 1;
if (possible && pos+m <= lim) solve(pos+m);
if (possible && pos-n >= 0) solve(pos-n);
arr[pos] = curVal++;
}
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
void go() {
cin >> n >> m;
vector <int> ans(1, 1);
k = max(n, m);
int l = k-1, r = n+m-1;
l = r = n + m - 1 - gcd(n, m);
while(l <= r) {
int mid = (l+r)>>1;
curVal = possible = 1;
for (int i = 0; i < 2*k+5; i++)
arr[i] = vis[i] = 0;
lim = mid;
for (int i = 0; i <= mid && possible; i++) {
if (vis[i]) continue;
solve(i);
}
if (!possible) {
r = mid-1;
} else {
l = mid+1;
vector <int> cur;
for (int i = 1; i <= mid; i++) cur.pb(arr[i] - arr[i-1]);
ans = cur;
}
}
cout << ans.size() << '\n';
for (auto el : ans) cout << -el << ' '; cout << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int T;
cin >> T;
while(T--) go();
}
Compilation message
sequence.cpp: In function 'void go()':
sequence.cpp:49:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
49 | for (auto el : ans) cout << -el << ' '; cout << '\n';
| ^~~
sequence.cpp:49:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
49 | for (auto el : ans) cout << -el << ' '; cout << '\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
332 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
1 ms |
332 KB |
Ok |
6 |
Correct |
0 ms |
320 KB |
Ok |
7 |
Correct |
1 ms |
332 KB |
Ok |
8 |
Correct |
1 ms |
332 KB |
Ok |
9 |
Correct |
1 ms |
332 KB |
Ok |
10 |
Correct |
0 ms |
332 KB |
Ok |
11 |
Correct |
0 ms |
332 KB |
Ok |
12 |
Correct |
0 ms |
332 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
324 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
2 ms |
460 KB |
Ok |
7 |
Correct |
7 ms |
1100 KB |
Ok |
8 |
Correct |
4 ms |
672 KB |
Ok |
9 |
Correct |
9 ms |
1220 KB |
Ok |
10 |
Correct |
5 ms |
756 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
320 KB |
Ok |
3 |
Correct |
1 ms |
324 KB |
Ok |
4 |
Correct |
1 ms |
332 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
0 ms |
332 KB |
Ok |
7 |
Correct |
0 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
1 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
0 ms |
324 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
332 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
70 ms |
12612 KB |
Ok |
7 |
Correct |
55 ms |
11180 KB |
Ok |
8 |
Correct |
119 ms |
15032 KB |
Ok |
9 |
Correct |
90 ms |
12416 KB |
Ok |
10 |
Correct |
56 ms |
8712 KB |
Ok |
11 |
Correct |
98 ms |
17036 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
332 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
1 ms |
332 KB |
Ok |
6 |
Correct |
0 ms |
320 KB |
Ok |
7 |
Correct |
1 ms |
332 KB |
Ok |
8 |
Correct |
1 ms |
332 KB |
Ok |
9 |
Correct |
1 ms |
332 KB |
Ok |
10 |
Correct |
0 ms |
332 KB |
Ok |
11 |
Correct |
0 ms |
332 KB |
Ok |
12 |
Correct |
0 ms |
332 KB |
Ok |
13 |
Correct |
0 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
320 KB |
Ok |
15 |
Correct |
1 ms |
324 KB |
Ok |
16 |
Correct |
1 ms |
332 KB |
Ok |
17 |
Correct |
0 ms |
204 KB |
Ok |
18 |
Correct |
0 ms |
332 KB |
Ok |
19 |
Correct |
0 ms |
204 KB |
Ok |
20 |
Correct |
0 ms |
204 KB |
Ok |
21 |
Correct |
1 ms |
204 KB |
Ok |
22 |
Correct |
1 ms |
204 KB |
Ok |
23 |
Correct |
0 ms |
324 KB |
Ok |
24 |
Correct |
2 ms |
332 KB |
Ok |
25 |
Correct |
2 ms |
332 KB |
Ok |
26 |
Correct |
2 ms |
332 KB |
Ok |
27 |
Correct |
2 ms |
324 KB |
Ok |
28 |
Correct |
1 ms |
332 KB |
Ok |
29 |
Correct |
1 ms |
332 KB |
Ok |
30 |
Correct |
2 ms |
332 KB |
Ok |
31 |
Correct |
2 ms |
316 KB |
Ok |
32 |
Correct |
2 ms |
332 KB |
Ok |
33 |
Correct |
2 ms |
332 KB |
Ok |
34 |
Correct |
3 ms |
588 KB |
Ok |
35 |
Correct |
3 ms |
588 KB |
Ok |
36 |
Correct |
3 ms |
716 KB |
Ok |
37 |
Correct |
3 ms |
580 KB |
Ok |
38 |
Correct |
3 ms |
628 KB |
Ok |
39 |
Correct |
3 ms |
588 KB |
Ok |
40 |
Correct |
3 ms |
588 KB |
Ok |
41 |
Correct |
3 ms |
588 KB |
Ok |
42 |
Correct |
3 ms |
716 KB |
Ok |
43 |
Correct |
3 ms |
716 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
332 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
1 ms |
332 KB |
Ok |
6 |
Correct |
0 ms |
320 KB |
Ok |
7 |
Correct |
1 ms |
332 KB |
Ok |
8 |
Correct |
1 ms |
332 KB |
Ok |
9 |
Correct |
1 ms |
332 KB |
Ok |
10 |
Correct |
0 ms |
332 KB |
Ok |
11 |
Correct |
0 ms |
332 KB |
Ok |
12 |
Correct |
0 ms |
332 KB |
Ok |
13 |
Correct |
1 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
324 KB |
Ok |
15 |
Correct |
0 ms |
204 KB |
Ok |
16 |
Correct |
1 ms |
204 KB |
Ok |
17 |
Correct |
1 ms |
204 KB |
Ok |
18 |
Correct |
2 ms |
460 KB |
Ok |
19 |
Correct |
7 ms |
1100 KB |
Ok |
20 |
Correct |
4 ms |
672 KB |
Ok |
21 |
Correct |
9 ms |
1220 KB |
Ok |
22 |
Correct |
5 ms |
756 KB |
Ok |
23 |
Correct |
0 ms |
204 KB |
Ok |
24 |
Correct |
0 ms |
320 KB |
Ok |
25 |
Correct |
1 ms |
324 KB |
Ok |
26 |
Correct |
1 ms |
332 KB |
Ok |
27 |
Correct |
0 ms |
204 KB |
Ok |
28 |
Correct |
0 ms |
332 KB |
Ok |
29 |
Correct |
0 ms |
204 KB |
Ok |
30 |
Correct |
0 ms |
204 KB |
Ok |
31 |
Correct |
1 ms |
204 KB |
Ok |
32 |
Correct |
1 ms |
204 KB |
Ok |
33 |
Correct |
0 ms |
324 KB |
Ok |
34 |
Correct |
2 ms |
332 KB |
Ok |
35 |
Correct |
2 ms |
332 KB |
Ok |
36 |
Correct |
2 ms |
332 KB |
Ok |
37 |
Correct |
2 ms |
324 KB |
Ok |
38 |
Correct |
1 ms |
332 KB |
Ok |
39 |
Correct |
1 ms |
332 KB |
Ok |
40 |
Correct |
2 ms |
332 KB |
Ok |
41 |
Correct |
2 ms |
316 KB |
Ok |
42 |
Correct |
2 ms |
332 KB |
Ok |
43 |
Correct |
2 ms |
332 KB |
Ok |
44 |
Correct |
3 ms |
588 KB |
Ok |
45 |
Correct |
3 ms |
588 KB |
Ok |
46 |
Correct |
3 ms |
716 KB |
Ok |
47 |
Correct |
3 ms |
580 KB |
Ok |
48 |
Correct |
3 ms |
628 KB |
Ok |
49 |
Correct |
3 ms |
588 KB |
Ok |
50 |
Correct |
3 ms |
588 KB |
Ok |
51 |
Correct |
3 ms |
588 KB |
Ok |
52 |
Correct |
3 ms |
716 KB |
Ok |
53 |
Correct |
3 ms |
716 KB |
Ok |
54 |
Correct |
51 ms |
3800 KB |
Ok |
55 |
Correct |
59 ms |
4248 KB |
Ok |
56 |
Correct |
59 ms |
3936 KB |
Ok |
57 |
Correct |
46 ms |
3172 KB |
Ok |
58 |
Correct |
62 ms |
3896 KB |
Ok |
59 |
Correct |
70 ms |
3808 KB |
Ok |
60 |
Correct |
44 ms |
3576 KB |
Ok |
61 |
Correct |
47 ms |
3444 KB |
Ok |
62 |
Correct |
63 ms |
4352 KB |
Ok |
63 |
Correct |
49 ms |
3552 KB |
Ok |
64 |
Correct |
56 ms |
4120 KB |
Ok |
65 |
Correct |
58 ms |
4064 KB |
Ok |
66 |
Correct |
51 ms |
3704 KB |
Ok |
67 |
Correct |
43 ms |
3408 KB |
Ok |
68 |
Correct |
55 ms |
3740 KB |
Ok |
69 |
Correct |
90 ms |
12288 KB |
Ok |
70 |
Correct |
113 ms |
12256 KB |
Ok |
71 |
Correct |
87 ms |
10108 KB |
Ok |
72 |
Correct |
94 ms |
12276 KB |
Ok |
73 |
Correct |
90 ms |
10476 KB |
Ok |
74 |
Correct |
89 ms |
11360 KB |
Ok |
75 |
Correct |
92 ms |
11980 KB |
Ok |
76 |
Correct |
91 ms |
12176 KB |
Ok |
77 |
Correct |
88 ms |
11016 KB |
Ok |
78 |
Correct |
90 ms |
12288 KB |
Ok |
79 |
Correct |
98 ms |
11624 KB |
Ok |
80 |
Correct |
87 ms |
10264 KB |
Ok |
81 |
Correct |
92 ms |
12272 KB |
Ok |
82 |
Correct |
87 ms |
11348 KB |
Ok |
83 |
Correct |
95 ms |
12284 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
332 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
1 ms |
332 KB |
Ok |
6 |
Correct |
0 ms |
320 KB |
Ok |
7 |
Correct |
1 ms |
332 KB |
Ok |
8 |
Correct |
1 ms |
332 KB |
Ok |
9 |
Correct |
1 ms |
332 KB |
Ok |
10 |
Correct |
0 ms |
332 KB |
Ok |
11 |
Correct |
0 ms |
332 KB |
Ok |
12 |
Correct |
0 ms |
332 KB |
Ok |
13 |
Correct |
1 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
324 KB |
Ok |
15 |
Correct |
0 ms |
204 KB |
Ok |
16 |
Correct |
1 ms |
204 KB |
Ok |
17 |
Correct |
1 ms |
204 KB |
Ok |
18 |
Correct |
2 ms |
460 KB |
Ok |
19 |
Correct |
7 ms |
1100 KB |
Ok |
20 |
Correct |
4 ms |
672 KB |
Ok |
21 |
Correct |
9 ms |
1220 KB |
Ok |
22 |
Correct |
5 ms |
756 KB |
Ok |
23 |
Correct |
0 ms |
204 KB |
Ok |
24 |
Correct |
0 ms |
320 KB |
Ok |
25 |
Correct |
1 ms |
324 KB |
Ok |
26 |
Correct |
1 ms |
332 KB |
Ok |
27 |
Correct |
0 ms |
204 KB |
Ok |
28 |
Correct |
0 ms |
332 KB |
Ok |
29 |
Correct |
0 ms |
204 KB |
Ok |
30 |
Correct |
0 ms |
204 KB |
Ok |
31 |
Correct |
1 ms |
204 KB |
Ok |
32 |
Correct |
1 ms |
204 KB |
Ok |
33 |
Correct |
0 ms |
324 KB |
Ok |
34 |
Correct |
0 ms |
204 KB |
Ok |
35 |
Correct |
0 ms |
332 KB |
Ok |
36 |
Correct |
0 ms |
204 KB |
Ok |
37 |
Correct |
1 ms |
204 KB |
Ok |
38 |
Correct |
0 ms |
204 KB |
Ok |
39 |
Correct |
70 ms |
12612 KB |
Ok |
40 |
Correct |
55 ms |
11180 KB |
Ok |
41 |
Correct |
119 ms |
15032 KB |
Ok |
42 |
Correct |
90 ms |
12416 KB |
Ok |
43 |
Correct |
56 ms |
8712 KB |
Ok |
44 |
Correct |
98 ms |
17036 KB |
Ok |
45 |
Correct |
2 ms |
332 KB |
Ok |
46 |
Correct |
2 ms |
332 KB |
Ok |
47 |
Correct |
2 ms |
332 KB |
Ok |
48 |
Correct |
2 ms |
324 KB |
Ok |
49 |
Correct |
1 ms |
332 KB |
Ok |
50 |
Correct |
1 ms |
332 KB |
Ok |
51 |
Correct |
2 ms |
332 KB |
Ok |
52 |
Correct |
2 ms |
316 KB |
Ok |
53 |
Correct |
2 ms |
332 KB |
Ok |
54 |
Correct |
2 ms |
332 KB |
Ok |
55 |
Correct |
3 ms |
588 KB |
Ok |
56 |
Correct |
3 ms |
588 KB |
Ok |
57 |
Correct |
3 ms |
716 KB |
Ok |
58 |
Correct |
3 ms |
580 KB |
Ok |
59 |
Correct |
3 ms |
628 KB |
Ok |
60 |
Correct |
3 ms |
588 KB |
Ok |
61 |
Correct |
3 ms |
588 KB |
Ok |
62 |
Correct |
3 ms |
588 KB |
Ok |
63 |
Correct |
3 ms |
716 KB |
Ok |
64 |
Correct |
3 ms |
716 KB |
Ok |
65 |
Correct |
51 ms |
3800 KB |
Ok |
66 |
Correct |
59 ms |
4248 KB |
Ok |
67 |
Correct |
59 ms |
3936 KB |
Ok |
68 |
Correct |
46 ms |
3172 KB |
Ok |
69 |
Correct |
62 ms |
3896 KB |
Ok |
70 |
Correct |
70 ms |
3808 KB |
Ok |
71 |
Correct |
44 ms |
3576 KB |
Ok |
72 |
Correct |
47 ms |
3444 KB |
Ok |
73 |
Correct |
63 ms |
4352 KB |
Ok |
74 |
Correct |
49 ms |
3552 KB |
Ok |
75 |
Correct |
56 ms |
4120 KB |
Ok |
76 |
Correct |
58 ms |
4064 KB |
Ok |
77 |
Correct |
51 ms |
3704 KB |
Ok |
78 |
Correct |
43 ms |
3408 KB |
Ok |
79 |
Correct |
55 ms |
3740 KB |
Ok |
80 |
Correct |
90 ms |
12288 KB |
Ok |
81 |
Correct |
113 ms |
12256 KB |
Ok |
82 |
Correct |
87 ms |
10108 KB |
Ok |
83 |
Correct |
94 ms |
12276 KB |
Ok |
84 |
Correct |
90 ms |
10476 KB |
Ok |
85 |
Correct |
89 ms |
11360 KB |
Ok |
86 |
Correct |
92 ms |
11980 KB |
Ok |
87 |
Correct |
91 ms |
12176 KB |
Ok |
88 |
Correct |
88 ms |
11016 KB |
Ok |
89 |
Correct |
90 ms |
12288 KB |
Ok |
90 |
Correct |
98 ms |
11624 KB |
Ok |
91 |
Correct |
87 ms |
10264 KB |
Ok |
92 |
Correct |
92 ms |
12272 KB |
Ok |
93 |
Correct |
87 ms |
11348 KB |
Ok |
94 |
Correct |
95 ms |
12284 KB |
Ok |
95 |
Correct |
132 ms |
9752 KB |
Ok |
96 |
Correct |
188 ms |
13596 KB |
Ok |
97 |
Correct |
182 ms |
11972 KB |
Ok |
98 |
Correct |
134 ms |
9992 KB |
Ok |
99 |
Correct |
159 ms |
10852 KB |
Ok |
100 |
Correct |
171 ms |
12024 KB |
Ok |
101 |
Correct |
165 ms |
12276 KB |
Ok |
102 |
Correct |
159 ms |
12744 KB |
Ok |
103 |
Correct |
156 ms |
11784 KB |
Ok |
104 |
Correct |
193 ms |
12644 KB |
Ok |
105 |
Correct |
196 ms |
13812 KB |
Ok |
106 |
Correct |
157 ms |
10908 KB |
Ok |
107 |
Correct |
173 ms |
12380 KB |
Ok |
108 |
Correct |
186 ms |
14096 KB |
Ok |
109 |
Correct |
169 ms |
11864 KB |
Ok |
110 |
Correct |
381 ms |
50520 KB |
Ok |
111 |
Correct |
383 ms |
51288 KB |
Ok |
112 |
Correct |
369 ms |
44808 KB |
Ok |
113 |
Correct |
363 ms |
50184 KB |
Ok |
114 |
Correct |
372 ms |
43412 KB |
Ok |
115 |
Correct |
394 ms |
51068 KB |
Ok |
116 |
Correct |
400 ms |
50280 KB |
Ok |
117 |
Correct |
362 ms |
51128 KB |
Ok |
118 |
Correct |
409 ms |
42108 KB |
Ok |
119 |
Correct |
407 ms |
50304 KB |
Ok |
120 |
Correct |
393 ms |
51204 KB |
Ok |
121 |
Correct |
380 ms |
47900 KB |
Ok |
122 |
Correct |
366 ms |
50900 KB |
Ok |
123 |
Correct |
373 ms |
47940 KB |
Ok |
124 |
Correct |
366 ms |
43908 KB |
Ok |
125 |
Correct |
333 ms |
34748 KB |
Ok |