/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 5 * 200005;
int gcd(int a, int b)
{
if (!a || !b)
return a + b;
return gcd(b, a % b);
}
LL lca(LL a, LL b)
{
return a * b / gcd(a, b);
}
int q, n, m, k, a[N], used[N], tin[N];
vector<int> t, g[N];
inline void dfs(int v)
{
used[v] = 1;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
if (used[to])
continue;
dfs(to);
}
//tin[v] = -t.size();
t.PB(v);
}
bool check(int x)
{
t.clear();
for (int i = 0; i <= x; i++)
{
g[i].clear();
used[i] = 0;
a[i] = i;
}
for (int i = 0; i <= x; i++)
{
if (i - m >= 0)
g[i - m].PB(i);
if (i + n <= x)
g[i + n].PB(i);
}
for (int i = 0; i <= x; i++)
if (!used[i])
dfs(i);
reverse(all(t));
//cout << "!!!!!" << x << endl;
for (int i = 0; i < t.size(); i++)
{
int v = t[i];
for (int j = 0; j < g[v].size(); j++)
{
int to = g[v][j];
// if (tin[to] <= tin[v])
// return 0;
//cout << v << " : " << to << endl;
a[to] = max(a[to], a[v] + 1);
}
}
return 1;
}
char uu[12];
void tp(int x)
{
if (x == 0)
{
putchar('0');
return;
}
if (x < 0)
{
putchar('-');
x *= (-1);
}
int i = 0;
while (x)
{
uu[i++] = (x % 10) + '0';
x /= 10;
}
for (i = i - 1; i >= 0; --i)
putchar(uu[i]);
}
int main()
{
cin >> q;
while (q--)
{
k = 0;
cin >> n >> m;
LL l, r, mid;
l = 0;
r = min(lca(n, m) - 1ll, 400000ll);
// while (l <= r)
// {
// mid = (l + r) / 2;
// if (check(mid))
// {
// k = mid;
// l = mid + 1;
// }
// else
// r = mid - 1;
// }
k = n + m - gcd(n, m) - 1;
check(k);
tp(k);
putchar('\n');
for (int i = 1; i <= k; i++)
{
//printf("%d ", a[i] - a[i - 1]);
tp(a[i] - a[i - 1]);
putchar(' ');
}
putchar('\n');
}
return 0;
}
/*
4
3 1
2 3
1 1
2 2
*/
Compilation message
sequence.cpp: In function 'void dfs(int)':
sequence.cpp:46:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++)
~~^~~~~~~~~~~~~
sequence.cpp: In function 'bool check(int)':
sequence.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < t.size(); i++)
~~^~~~~~~~~~
sequence.cpp:82:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < g[v].size(); j++)
~~^~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:124:12: warning: variable 'l' set but not used [-Wunused-but-set-variable]
LL l, r, mid;
^
sequence.cpp:124:15: warning: variable 'r' set but not used [-Wunused-but-set-variable]
LL l, r, mid;
^
sequence.cpp:124:18: warning: unused variable 'mid' [-Wunused-variable]
LL l, r, mid;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23672 KB |
Ok |
2 |
Correct |
24 ms |
23800 KB |
Ok |
3 |
Correct |
24 ms |
23884 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23928 KB |
Ok |
6 |
Correct |
23 ms |
23928 KB |
Ok |
7 |
Correct |
23 ms |
23800 KB |
Ok |
8 |
Correct |
23 ms |
23800 KB |
Ok |
9 |
Correct |
24 ms |
23800 KB |
Ok |
10 |
Correct |
23 ms |
23800 KB |
Ok |
11 |
Correct |
24 ms |
23800 KB |
Ok |
12 |
Correct |
27 ms |
23800 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Ok |
2 |
Correct |
23 ms |
23772 KB |
Ok |
3 |
Correct |
23 ms |
23800 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23800 KB |
Ok |
6 |
Correct |
25 ms |
23928 KB |
Ok |
7 |
Correct |
33 ms |
24696 KB |
Ok |
8 |
Correct |
28 ms |
24184 KB |
Ok |
9 |
Correct |
35 ms |
24776 KB |
Ok |
10 |
Correct |
35 ms |
24312 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Ok |
2 |
Correct |
24 ms |
23800 KB |
Ok |
3 |
Correct |
23 ms |
23800 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23800 KB |
Ok |
6 |
Correct |
23 ms |
23800 KB |
Ok |
7 |
Correct |
27 ms |
23800 KB |
Ok |
8 |
Correct |
27 ms |
23800 KB |
Ok |
9 |
Correct |
23 ms |
23800 KB |
Ok |
10 |
Correct |
28 ms |
23800 KB |
Ok |
11 |
Correct |
23 ms |
23800 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Ok |
2 |
Correct |
23 ms |
23800 KB |
Ok |
3 |
Correct |
23 ms |
23772 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23800 KB |
Ok |
6 |
Correct |
120 ms |
36716 KB |
Ok |
7 |
Correct |
102 ms |
37104 KB |
Ok |
8 |
Correct |
166 ms |
39600 KB |
Ok |
9 |
Correct |
168 ms |
37360 KB |
Ok |
10 |
Correct |
88 ms |
32496 KB |
Ok |
11 |
Correct |
148 ms |
39532 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23672 KB |
Ok |
2 |
Correct |
24 ms |
23800 KB |
Ok |
3 |
Correct |
24 ms |
23884 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23928 KB |
Ok |
6 |
Correct |
23 ms |
23928 KB |
Ok |
7 |
Correct |
23 ms |
23800 KB |
Ok |
8 |
Correct |
23 ms |
23800 KB |
Ok |
9 |
Correct |
24 ms |
23800 KB |
Ok |
10 |
Correct |
23 ms |
23800 KB |
Ok |
11 |
Correct |
24 ms |
23800 KB |
Ok |
12 |
Correct |
27 ms |
23800 KB |
Ok |
13 |
Correct |
23 ms |
23800 KB |
Ok |
14 |
Correct |
24 ms |
23800 KB |
Ok |
15 |
Correct |
23 ms |
23800 KB |
Ok |
16 |
Correct |
23 ms |
23800 KB |
Ok |
17 |
Correct |
23 ms |
23800 KB |
Ok |
18 |
Correct |
23 ms |
23800 KB |
Ok |
19 |
Correct |
27 ms |
23800 KB |
Ok |
20 |
Correct |
27 ms |
23800 KB |
Ok |
21 |
Correct |
23 ms |
23800 KB |
Ok |
22 |
Correct |
28 ms |
23800 KB |
Ok |
23 |
Correct |
23 ms |
23800 KB |
Ok |
24 |
Correct |
24 ms |
24056 KB |
Ok |
25 |
Correct |
25 ms |
24064 KB |
Ok |
26 |
Correct |
24 ms |
23928 KB |
Ok |
27 |
Correct |
24 ms |
23928 KB |
Ok |
28 |
Correct |
24 ms |
23928 KB |
Ok |
29 |
Correct |
29 ms |
23928 KB |
Ok |
30 |
Correct |
24 ms |
23928 KB |
Ok |
31 |
Correct |
25 ms |
23928 KB |
Ok |
32 |
Correct |
25 ms |
23928 KB |
Ok |
33 |
Correct |
25 ms |
24056 KB |
Ok |
34 |
Correct |
27 ms |
24056 KB |
Ok |
35 |
Correct |
29 ms |
24184 KB |
Ok |
36 |
Correct |
28 ms |
24184 KB |
Ok |
37 |
Correct |
29 ms |
24184 KB |
Ok |
38 |
Correct |
28 ms |
24184 KB |
Ok |
39 |
Correct |
27 ms |
24056 KB |
Ok |
40 |
Correct |
28 ms |
24184 KB |
Ok |
41 |
Correct |
28 ms |
24188 KB |
Ok |
42 |
Correct |
28 ms |
24184 KB |
Ok |
43 |
Correct |
28 ms |
24164 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23672 KB |
Ok |
2 |
Correct |
24 ms |
23800 KB |
Ok |
3 |
Correct |
24 ms |
23884 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23928 KB |
Ok |
6 |
Correct |
23 ms |
23928 KB |
Ok |
7 |
Correct |
23 ms |
23800 KB |
Ok |
8 |
Correct |
23 ms |
23800 KB |
Ok |
9 |
Correct |
24 ms |
23800 KB |
Ok |
10 |
Correct |
23 ms |
23800 KB |
Ok |
11 |
Correct |
24 ms |
23800 KB |
Ok |
12 |
Correct |
27 ms |
23800 KB |
Ok |
13 |
Correct |
23 ms |
23800 KB |
Ok |
14 |
Correct |
23 ms |
23772 KB |
Ok |
15 |
Correct |
23 ms |
23800 KB |
Ok |
16 |
Correct |
23 ms |
23800 KB |
Ok |
17 |
Correct |
23 ms |
23800 KB |
Ok |
18 |
Correct |
25 ms |
23928 KB |
Ok |
19 |
Correct |
33 ms |
24696 KB |
Ok |
20 |
Correct |
28 ms |
24184 KB |
Ok |
21 |
Correct |
35 ms |
24776 KB |
Ok |
22 |
Correct |
35 ms |
24312 KB |
Ok |
23 |
Correct |
23 ms |
23800 KB |
Ok |
24 |
Correct |
24 ms |
23800 KB |
Ok |
25 |
Correct |
23 ms |
23800 KB |
Ok |
26 |
Correct |
23 ms |
23800 KB |
Ok |
27 |
Correct |
23 ms |
23800 KB |
Ok |
28 |
Correct |
23 ms |
23800 KB |
Ok |
29 |
Correct |
27 ms |
23800 KB |
Ok |
30 |
Correct |
27 ms |
23800 KB |
Ok |
31 |
Correct |
23 ms |
23800 KB |
Ok |
32 |
Correct |
28 ms |
23800 KB |
Ok |
33 |
Correct |
23 ms |
23800 KB |
Ok |
34 |
Correct |
24 ms |
24056 KB |
Ok |
35 |
Correct |
25 ms |
24064 KB |
Ok |
36 |
Correct |
24 ms |
23928 KB |
Ok |
37 |
Correct |
24 ms |
23928 KB |
Ok |
38 |
Correct |
24 ms |
23928 KB |
Ok |
39 |
Correct |
29 ms |
23928 KB |
Ok |
40 |
Correct |
24 ms |
23928 KB |
Ok |
41 |
Correct |
25 ms |
23928 KB |
Ok |
42 |
Correct |
25 ms |
23928 KB |
Ok |
43 |
Correct |
25 ms |
24056 KB |
Ok |
44 |
Correct |
27 ms |
24056 KB |
Ok |
45 |
Correct |
29 ms |
24184 KB |
Ok |
46 |
Correct |
28 ms |
24184 KB |
Ok |
47 |
Correct |
29 ms |
24184 KB |
Ok |
48 |
Correct |
28 ms |
24184 KB |
Ok |
49 |
Correct |
27 ms |
24056 KB |
Ok |
50 |
Correct |
28 ms |
24184 KB |
Ok |
51 |
Correct |
28 ms |
24188 KB |
Ok |
52 |
Correct |
28 ms |
24184 KB |
Ok |
53 |
Correct |
28 ms |
24164 KB |
Ok |
54 |
Correct |
79 ms |
29300 KB |
Ok |
55 |
Correct |
83 ms |
29300 KB |
Ok |
56 |
Correct |
83 ms |
29424 KB |
Ok |
57 |
Correct |
66 ms |
28656 KB |
Ok |
58 |
Correct |
82 ms |
29168 KB |
Ok |
59 |
Correct |
80 ms |
28912 KB |
Ok |
60 |
Correct |
72 ms |
28528 KB |
Ok |
61 |
Correct |
69 ms |
29040 KB |
Ok |
62 |
Correct |
95 ms |
29372 KB |
Ok |
63 |
Correct |
89 ms |
28728 KB |
Ok |
64 |
Correct |
120 ms |
29292 KB |
Ok |
65 |
Correct |
84 ms |
29296 KB |
Ok |
66 |
Correct |
70 ms |
29164 KB |
Ok |
67 |
Correct |
68 ms |
28784 KB |
Ok |
68 |
Correct |
84 ms |
29168 KB |
Ok |
69 |
Correct |
287 ms |
35316 KB |
Ok |
70 |
Correct |
355 ms |
36340 KB |
Ok |
71 |
Correct |
276 ms |
33648 KB |
Ok |
72 |
Correct |
286 ms |
35800 KB |
Ok |
73 |
Correct |
285 ms |
34252 KB |
Ok |
74 |
Correct |
289 ms |
33776 KB |
Ok |
75 |
Correct |
356 ms |
33936 KB |
Ok |
76 |
Correct |
306 ms |
36212 KB |
Ok |
77 |
Correct |
238 ms |
33136 KB |
Ok |
78 |
Correct |
338 ms |
36316 KB |
Ok |
79 |
Correct |
303 ms |
34932 KB |
Ok |
80 |
Correct |
265 ms |
34456 KB |
Ok |
81 |
Correct |
357 ms |
35656 KB |
Ok |
82 |
Correct |
371 ms |
35188 KB |
Ok |
83 |
Correct |
251 ms |
34192 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23672 KB |
Ok |
2 |
Correct |
24 ms |
23800 KB |
Ok |
3 |
Correct |
24 ms |
23884 KB |
Ok |
4 |
Correct |
23 ms |
23800 KB |
Ok |
5 |
Correct |
23 ms |
23928 KB |
Ok |
6 |
Correct |
23 ms |
23928 KB |
Ok |
7 |
Correct |
23 ms |
23800 KB |
Ok |
8 |
Correct |
23 ms |
23800 KB |
Ok |
9 |
Correct |
24 ms |
23800 KB |
Ok |
10 |
Correct |
23 ms |
23800 KB |
Ok |
11 |
Correct |
24 ms |
23800 KB |
Ok |
12 |
Correct |
27 ms |
23800 KB |
Ok |
13 |
Correct |
23 ms |
23800 KB |
Ok |
14 |
Correct |
23 ms |
23772 KB |
Ok |
15 |
Correct |
23 ms |
23800 KB |
Ok |
16 |
Correct |
23 ms |
23800 KB |
Ok |
17 |
Correct |
23 ms |
23800 KB |
Ok |
18 |
Correct |
25 ms |
23928 KB |
Ok |
19 |
Correct |
33 ms |
24696 KB |
Ok |
20 |
Correct |
28 ms |
24184 KB |
Ok |
21 |
Correct |
35 ms |
24776 KB |
Ok |
22 |
Correct |
35 ms |
24312 KB |
Ok |
23 |
Correct |
23 ms |
23800 KB |
Ok |
24 |
Correct |
24 ms |
23800 KB |
Ok |
25 |
Correct |
23 ms |
23800 KB |
Ok |
26 |
Correct |
23 ms |
23800 KB |
Ok |
27 |
Correct |
23 ms |
23800 KB |
Ok |
28 |
Correct |
23 ms |
23800 KB |
Ok |
29 |
Correct |
27 ms |
23800 KB |
Ok |
30 |
Correct |
27 ms |
23800 KB |
Ok |
31 |
Correct |
23 ms |
23800 KB |
Ok |
32 |
Correct |
28 ms |
23800 KB |
Ok |
33 |
Correct |
23 ms |
23800 KB |
Ok |
34 |
Correct |
23 ms |
23800 KB |
Ok |
35 |
Correct |
23 ms |
23800 KB |
Ok |
36 |
Correct |
23 ms |
23772 KB |
Ok |
37 |
Correct |
23 ms |
23800 KB |
Ok |
38 |
Correct |
23 ms |
23800 KB |
Ok |
39 |
Correct |
120 ms |
36716 KB |
Ok |
40 |
Correct |
102 ms |
37104 KB |
Ok |
41 |
Correct |
166 ms |
39600 KB |
Ok |
42 |
Correct |
168 ms |
37360 KB |
Ok |
43 |
Correct |
88 ms |
32496 KB |
Ok |
44 |
Correct |
148 ms |
39532 KB |
Ok |
45 |
Correct |
24 ms |
24056 KB |
Ok |
46 |
Correct |
25 ms |
24064 KB |
Ok |
47 |
Correct |
24 ms |
23928 KB |
Ok |
48 |
Correct |
24 ms |
23928 KB |
Ok |
49 |
Correct |
24 ms |
23928 KB |
Ok |
50 |
Correct |
29 ms |
23928 KB |
Ok |
51 |
Correct |
24 ms |
23928 KB |
Ok |
52 |
Correct |
25 ms |
23928 KB |
Ok |
53 |
Correct |
25 ms |
23928 KB |
Ok |
54 |
Correct |
25 ms |
24056 KB |
Ok |
55 |
Correct |
27 ms |
24056 KB |
Ok |
56 |
Correct |
29 ms |
24184 KB |
Ok |
57 |
Correct |
28 ms |
24184 KB |
Ok |
58 |
Correct |
29 ms |
24184 KB |
Ok |
59 |
Correct |
28 ms |
24184 KB |
Ok |
60 |
Correct |
27 ms |
24056 KB |
Ok |
61 |
Correct |
28 ms |
24184 KB |
Ok |
62 |
Correct |
28 ms |
24188 KB |
Ok |
63 |
Correct |
28 ms |
24184 KB |
Ok |
64 |
Correct |
28 ms |
24164 KB |
Ok |
65 |
Correct |
79 ms |
29300 KB |
Ok |
66 |
Correct |
83 ms |
29300 KB |
Ok |
67 |
Correct |
83 ms |
29424 KB |
Ok |
68 |
Correct |
66 ms |
28656 KB |
Ok |
69 |
Correct |
82 ms |
29168 KB |
Ok |
70 |
Correct |
80 ms |
28912 KB |
Ok |
71 |
Correct |
72 ms |
28528 KB |
Ok |
72 |
Correct |
69 ms |
29040 KB |
Ok |
73 |
Correct |
95 ms |
29372 KB |
Ok |
74 |
Correct |
89 ms |
28728 KB |
Ok |
75 |
Correct |
120 ms |
29292 KB |
Ok |
76 |
Correct |
84 ms |
29296 KB |
Ok |
77 |
Correct |
70 ms |
29164 KB |
Ok |
78 |
Correct |
68 ms |
28784 KB |
Ok |
79 |
Correct |
84 ms |
29168 KB |
Ok |
80 |
Correct |
287 ms |
35316 KB |
Ok |
81 |
Correct |
355 ms |
36340 KB |
Ok |
82 |
Correct |
276 ms |
33648 KB |
Ok |
83 |
Correct |
286 ms |
35800 KB |
Ok |
84 |
Correct |
285 ms |
34252 KB |
Ok |
85 |
Correct |
289 ms |
33776 KB |
Ok |
86 |
Correct |
356 ms |
33936 KB |
Ok |
87 |
Correct |
306 ms |
36212 KB |
Ok |
88 |
Correct |
238 ms |
33136 KB |
Ok |
89 |
Correct |
338 ms |
36316 KB |
Ok |
90 |
Correct |
303 ms |
34932 KB |
Ok |
91 |
Correct |
265 ms |
34456 KB |
Ok |
92 |
Correct |
357 ms |
35656 KB |
Ok |
93 |
Correct |
371 ms |
35188 KB |
Ok |
94 |
Correct |
251 ms |
34192 KB |
Ok |
95 |
Correct |
179 ms |
37632 KB |
Ok |
96 |
Correct |
340 ms |
44028 KB |
Ok |
97 |
Correct |
281 ms |
40708 KB |
Ok |
98 |
Correct |
196 ms |
40808 KB |
Ok |
99 |
Correct |
190 ms |
40424 KB |
Ok |
100 |
Correct |
273 ms |
39780 KB |
Ok |
101 |
Correct |
215 ms |
42980 KB |
Ok |
102 |
Correct |
330 ms |
40808 KB |
Ok |
103 |
Correct |
265 ms |
41700 KB |
Ok |
104 |
Correct |
284 ms |
43108 KB |
Ok |
105 |
Correct |
345 ms |
43756 KB |
Ok |
106 |
Correct |
258 ms |
43748 KB |
Ok |
107 |
Correct |
291 ms |
43116 KB |
Ok |
108 |
Correct |
374 ms |
43464 KB |
Ok |
109 |
Correct |
301 ms |
44648 KB |
Ok |
110 |
Execution timed out |
2041 ms |
64584 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |