#include <bits/stdc++.h>
using namespace std;
int vis [400010]; long long int c=0; long long int n, m;
vector < int > g [400010];
vector < long long int > ans;
long long int o [400010];
int vis2 [400010];
int vis3 [400010];
void dfs ( int x, long long int d){
if (vis [x]) return ;
vis [x]=1;
if (x+n<=d){
g [x+n].push_back (x); //dfs (x+n, d);
}
if (x+m<=d){
g [x].push_back (x+m); dfs (x+m, d);
}
return ;
}
void dfs2 ( int v) {
vis2[v]=1;
for ( long long int u : g[v]) {
if (!vis2[u]) dfs2(u);
}
ans.push_back(v);
return ;
}
void is_cycle ( long long int x) {
if (vis3 [x]==1){
c=1; return ;
}
if (vis3 [x]) return ;
vis3 [x]=1;
for ( long long int u : g[x]) is_cycle (u);
vis3 [x]=2;
return ;
}
void sort_top( long long int d) {
memset (vis2, 0, sizeof vis2); ans.clear();
for ( long long int i=0; i<=d; i++) {
if (!vis2[i])
dfs2(i);
}
reverse(ans.begin(), ans.end());
return ;
}
long long int ok ( long long int d){
memset (vis, 0, sizeof vis);
memset (vis3, 0, sizeof vis3);
c=0;
for ( long long int i=0; i<400010; i++) g [i].clear();
for ( long long int i=0; i<=d; i++){
if (!vis [i]) dfs (i, d);
}
for ( long long int i=1; i<=d; i++) is_cycle (i);
if (c) return 0;
sort_top (d);
return 1;
}
int main(){
long long int t; cin >> t;
while (t--){
ans.clear ();
cin >> n >> m;
ok (n+m-__gcd(n,m)-1);
int lo=n+m-__gcd(n,m)-1;
cout << lo << endl;
if (lo==0) continue;
long long int pr=0;
for ( long long int i=0; i<=lo; i++){
if (ans [lo]==0) break;
pr--;
}
for ( long long int i=0; i<=lo; i++){
//cout << ans [i] << " ";
o [ans [i]]=pr; pr++;
}
for ( long long int i=1; i<lo+1; i++){
//cout << o [i] << "x";
cout << o [i]-o [i-1] << " ";
}
cout << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
14292 KB |
Ok |
2 |
Correct |
19 ms |
14364 KB |
Ok |
3 |
Correct |
20 ms |
14404 KB |
Ok |
4 |
Correct |
19 ms |
14292 KB |
Ok |
5 |
Correct |
19 ms |
14392 KB |
Ok |
6 |
Correct |
20 ms |
14292 KB |
Ok |
7 |
Correct |
18 ms |
14292 KB |
Ok |
8 |
Correct |
19 ms |
14292 KB |
Ok |
9 |
Correct |
20 ms |
14292 KB |
Ok |
10 |
Correct |
18 ms |
14292 KB |
Ok |
11 |
Correct |
18 ms |
14352 KB |
Ok |
12 |
Correct |
18 ms |
14292 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
14292 KB |
Ok |
2 |
Correct |
21 ms |
14420 KB |
Ok |
3 |
Correct |
21 ms |
14292 KB |
Ok |
4 |
Correct |
19 ms |
14292 KB |
Ok |
5 |
Correct |
22 ms |
14292 KB |
Ok |
6 |
Correct |
22 ms |
14548 KB |
Ok |
7 |
Correct |
29 ms |
15700 KB |
Ok |
8 |
Correct |
23 ms |
14964 KB |
Ok |
9 |
Correct |
30 ms |
15948 KB |
Ok |
10 |
Correct |
25 ms |
15128 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14292 KB |
Ok |
2 |
Correct |
21 ms |
14292 KB |
Ok |
3 |
Correct |
18 ms |
14292 KB |
Ok |
4 |
Correct |
18 ms |
14336 KB |
Ok |
5 |
Correct |
21 ms |
14292 KB |
Ok |
6 |
Correct |
19 ms |
14292 KB |
Ok |
7 |
Correct |
19 ms |
14292 KB |
Ok |
8 |
Correct |
19 ms |
14292 KB |
Ok |
9 |
Correct |
23 ms |
14292 KB |
Ok |
10 |
Correct |
19 ms |
14292 KB |
Ok |
11 |
Correct |
20 ms |
14292 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
14292 KB |
Ok |
2 |
Correct |
18 ms |
14292 KB |
Ok |
3 |
Correct |
17 ms |
14316 KB |
Ok |
4 |
Correct |
18 ms |
14292 KB |
Ok |
5 |
Correct |
19 ms |
14292 KB |
Ok |
6 |
Correct |
134 ms |
35280 KB |
Ok |
7 |
Correct |
107 ms |
34896 KB |
Ok |
8 |
Correct |
180 ms |
38328 KB |
Ok |
9 |
Correct |
155 ms |
35776 KB |
Ok |
10 |
Correct |
100 ms |
28456 KB |
Ok |
11 |
Correct |
158 ms |
40708 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
14292 KB |
Ok |
2 |
Correct |
19 ms |
14364 KB |
Ok |
3 |
Correct |
20 ms |
14404 KB |
Ok |
4 |
Correct |
19 ms |
14292 KB |
Ok |
5 |
Correct |
19 ms |
14392 KB |
Ok |
6 |
Correct |
20 ms |
14292 KB |
Ok |
7 |
Correct |
18 ms |
14292 KB |
Ok |
8 |
Correct |
19 ms |
14292 KB |
Ok |
9 |
Correct |
20 ms |
14292 KB |
Ok |
10 |
Correct |
18 ms |
14292 KB |
Ok |
11 |
Correct |
18 ms |
14352 KB |
Ok |
12 |
Correct |
18 ms |
14292 KB |
Ok |
13 |
Correct |
10 ms |
14292 KB |
Ok |
14 |
Correct |
21 ms |
14292 KB |
Ok |
15 |
Correct |
18 ms |
14292 KB |
Ok |
16 |
Correct |
18 ms |
14336 KB |
Ok |
17 |
Correct |
21 ms |
14292 KB |
Ok |
18 |
Correct |
19 ms |
14292 KB |
Ok |
19 |
Correct |
19 ms |
14292 KB |
Ok |
20 |
Correct |
19 ms |
14292 KB |
Ok |
21 |
Correct |
23 ms |
14292 KB |
Ok |
22 |
Correct |
19 ms |
14292 KB |
Ok |
23 |
Correct |
20 ms |
14292 KB |
Ok |
24 |
Correct |
21 ms |
14556 KB |
Ok |
25 |
Correct |
21 ms |
14616 KB |
Ok |
26 |
Correct |
20 ms |
14560 KB |
Ok |
27 |
Correct |
20 ms |
14552 KB |
Ok |
28 |
Correct |
20 ms |
14552 KB |
Ok |
29 |
Correct |
21 ms |
14568 KB |
Ok |
30 |
Correct |
20 ms |
14476 KB |
Ok |
31 |
Correct |
20 ms |
14580 KB |
Ok |
32 |
Correct |
21 ms |
14588 KB |
Ok |
33 |
Correct |
23 ms |
14496 KB |
Ok |
34 |
Correct |
27 ms |
14804 KB |
Ok |
35 |
Correct |
23 ms |
14816 KB |
Ok |
36 |
Correct |
23 ms |
14924 KB |
Ok |
37 |
Correct |
23 ms |
14932 KB |
Ok |
38 |
Correct |
22 ms |
14804 KB |
Ok |
39 |
Correct |
23 ms |
14880 KB |
Ok |
40 |
Correct |
24 ms |
14892 KB |
Ok |
41 |
Correct |
24 ms |
14880 KB |
Ok |
42 |
Correct |
26 ms |
14980 KB |
Ok |
43 |
Correct |
24 ms |
14872 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
14292 KB |
Ok |
2 |
Correct |
19 ms |
14364 KB |
Ok |
3 |
Correct |
20 ms |
14404 KB |
Ok |
4 |
Correct |
19 ms |
14292 KB |
Ok |
5 |
Correct |
19 ms |
14392 KB |
Ok |
6 |
Correct |
20 ms |
14292 KB |
Ok |
7 |
Correct |
18 ms |
14292 KB |
Ok |
8 |
Correct |
19 ms |
14292 KB |
Ok |
9 |
Correct |
20 ms |
14292 KB |
Ok |
10 |
Correct |
18 ms |
14292 KB |
Ok |
11 |
Correct |
18 ms |
14352 KB |
Ok |
12 |
Correct |
18 ms |
14292 KB |
Ok |
13 |
Correct |
18 ms |
14292 KB |
Ok |
14 |
Correct |
21 ms |
14420 KB |
Ok |
15 |
Correct |
21 ms |
14292 KB |
Ok |
16 |
Correct |
19 ms |
14292 KB |
Ok |
17 |
Correct |
22 ms |
14292 KB |
Ok |
18 |
Correct |
22 ms |
14548 KB |
Ok |
19 |
Correct |
29 ms |
15700 KB |
Ok |
20 |
Correct |
23 ms |
14964 KB |
Ok |
21 |
Correct |
30 ms |
15948 KB |
Ok |
22 |
Correct |
25 ms |
15128 KB |
Ok |
23 |
Correct |
10 ms |
14292 KB |
Ok |
24 |
Correct |
21 ms |
14292 KB |
Ok |
25 |
Correct |
18 ms |
14292 KB |
Ok |
26 |
Correct |
18 ms |
14336 KB |
Ok |
27 |
Correct |
21 ms |
14292 KB |
Ok |
28 |
Correct |
19 ms |
14292 KB |
Ok |
29 |
Correct |
19 ms |
14292 KB |
Ok |
30 |
Correct |
19 ms |
14292 KB |
Ok |
31 |
Correct |
23 ms |
14292 KB |
Ok |
32 |
Correct |
19 ms |
14292 KB |
Ok |
33 |
Correct |
20 ms |
14292 KB |
Ok |
34 |
Correct |
21 ms |
14556 KB |
Ok |
35 |
Correct |
21 ms |
14616 KB |
Ok |
36 |
Correct |
20 ms |
14560 KB |
Ok |
37 |
Correct |
20 ms |
14552 KB |
Ok |
38 |
Correct |
20 ms |
14552 KB |
Ok |
39 |
Correct |
21 ms |
14568 KB |
Ok |
40 |
Correct |
20 ms |
14476 KB |
Ok |
41 |
Correct |
20 ms |
14580 KB |
Ok |
42 |
Correct |
21 ms |
14588 KB |
Ok |
43 |
Correct |
23 ms |
14496 KB |
Ok |
44 |
Correct |
27 ms |
14804 KB |
Ok |
45 |
Correct |
23 ms |
14816 KB |
Ok |
46 |
Correct |
23 ms |
14924 KB |
Ok |
47 |
Correct |
23 ms |
14932 KB |
Ok |
48 |
Correct |
22 ms |
14804 KB |
Ok |
49 |
Correct |
23 ms |
14880 KB |
Ok |
50 |
Correct |
24 ms |
14892 KB |
Ok |
51 |
Correct |
24 ms |
14880 KB |
Ok |
52 |
Correct |
26 ms |
14980 KB |
Ok |
53 |
Correct |
24 ms |
14872 KB |
Ok |
54 |
Correct |
90 ms |
20876 KB |
Ok |
55 |
Correct |
112 ms |
21180 KB |
Ok |
56 |
Correct |
100 ms |
21240 KB |
Ok |
57 |
Correct |
83 ms |
20152 KB |
Ok |
58 |
Correct |
103 ms |
21072 KB |
Ok |
59 |
Correct |
99 ms |
20616 KB |
Ok |
60 |
Correct |
82 ms |
20140 KB |
Ok |
61 |
Correct |
82 ms |
20564 KB |
Ok |
62 |
Correct |
116 ms |
21436 KB |
Ok |
63 |
Correct |
87 ms |
20404 KB |
Ok |
64 |
Correct |
101 ms |
21124 KB |
Ok |
65 |
Correct |
103 ms |
21052 KB |
Ok |
66 |
Correct |
90 ms |
20664 KB |
Ok |
67 |
Correct |
81 ms |
20408 KB |
Ok |
68 |
Correct |
98 ms |
20996 KB |
Ok |
69 |
Correct |
254 ms |
31216 KB |
Ok |
70 |
Correct |
294 ms |
31168 KB |
Ok |
71 |
Correct |
254 ms |
29832 KB |
Ok |
72 |
Correct |
269 ms |
31300 KB |
Ok |
73 |
Correct |
241 ms |
28936 KB |
Ok |
74 |
Correct |
249 ms |
30040 KB |
Ok |
75 |
Correct |
255 ms |
30920 KB |
Ok |
76 |
Correct |
263 ms |
31144 KB |
Ok |
77 |
Correct |
264 ms |
29580 KB |
Ok |
78 |
Correct |
244 ms |
31512 KB |
Ok |
79 |
Correct |
278 ms |
30296 KB |
Ok |
80 |
Correct |
257 ms |
29716 KB |
Ok |
81 |
Correct |
270 ms |
31120 KB |
Ok |
82 |
Correct |
238 ms |
30116 KB |
Ok |
83 |
Correct |
248 ms |
31556 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
14292 KB |
Ok |
2 |
Correct |
19 ms |
14364 KB |
Ok |
3 |
Correct |
20 ms |
14404 KB |
Ok |
4 |
Correct |
19 ms |
14292 KB |
Ok |
5 |
Correct |
19 ms |
14392 KB |
Ok |
6 |
Correct |
20 ms |
14292 KB |
Ok |
7 |
Correct |
18 ms |
14292 KB |
Ok |
8 |
Correct |
19 ms |
14292 KB |
Ok |
9 |
Correct |
20 ms |
14292 KB |
Ok |
10 |
Correct |
18 ms |
14292 KB |
Ok |
11 |
Correct |
18 ms |
14352 KB |
Ok |
12 |
Correct |
18 ms |
14292 KB |
Ok |
13 |
Correct |
18 ms |
14292 KB |
Ok |
14 |
Correct |
21 ms |
14420 KB |
Ok |
15 |
Correct |
21 ms |
14292 KB |
Ok |
16 |
Correct |
19 ms |
14292 KB |
Ok |
17 |
Correct |
22 ms |
14292 KB |
Ok |
18 |
Correct |
22 ms |
14548 KB |
Ok |
19 |
Correct |
29 ms |
15700 KB |
Ok |
20 |
Correct |
23 ms |
14964 KB |
Ok |
21 |
Correct |
30 ms |
15948 KB |
Ok |
22 |
Correct |
25 ms |
15128 KB |
Ok |
23 |
Correct |
10 ms |
14292 KB |
Ok |
24 |
Correct |
21 ms |
14292 KB |
Ok |
25 |
Correct |
18 ms |
14292 KB |
Ok |
26 |
Correct |
18 ms |
14336 KB |
Ok |
27 |
Correct |
21 ms |
14292 KB |
Ok |
28 |
Correct |
19 ms |
14292 KB |
Ok |
29 |
Correct |
19 ms |
14292 KB |
Ok |
30 |
Correct |
19 ms |
14292 KB |
Ok |
31 |
Correct |
23 ms |
14292 KB |
Ok |
32 |
Correct |
19 ms |
14292 KB |
Ok |
33 |
Correct |
20 ms |
14292 KB |
Ok |
34 |
Correct |
18 ms |
14292 KB |
Ok |
35 |
Correct |
18 ms |
14292 KB |
Ok |
36 |
Correct |
17 ms |
14316 KB |
Ok |
37 |
Correct |
18 ms |
14292 KB |
Ok |
38 |
Correct |
19 ms |
14292 KB |
Ok |
39 |
Correct |
134 ms |
35280 KB |
Ok |
40 |
Correct |
107 ms |
34896 KB |
Ok |
41 |
Correct |
180 ms |
38328 KB |
Ok |
42 |
Correct |
155 ms |
35776 KB |
Ok |
43 |
Correct |
100 ms |
28456 KB |
Ok |
44 |
Correct |
158 ms |
40708 KB |
Ok |
45 |
Correct |
21 ms |
14556 KB |
Ok |
46 |
Correct |
21 ms |
14616 KB |
Ok |
47 |
Correct |
20 ms |
14560 KB |
Ok |
48 |
Correct |
20 ms |
14552 KB |
Ok |
49 |
Correct |
20 ms |
14552 KB |
Ok |
50 |
Correct |
21 ms |
14568 KB |
Ok |
51 |
Correct |
20 ms |
14476 KB |
Ok |
52 |
Correct |
20 ms |
14580 KB |
Ok |
53 |
Correct |
21 ms |
14588 KB |
Ok |
54 |
Correct |
23 ms |
14496 KB |
Ok |
55 |
Correct |
27 ms |
14804 KB |
Ok |
56 |
Correct |
23 ms |
14816 KB |
Ok |
57 |
Correct |
23 ms |
14924 KB |
Ok |
58 |
Correct |
23 ms |
14932 KB |
Ok |
59 |
Correct |
22 ms |
14804 KB |
Ok |
60 |
Correct |
23 ms |
14880 KB |
Ok |
61 |
Correct |
24 ms |
14892 KB |
Ok |
62 |
Correct |
24 ms |
14880 KB |
Ok |
63 |
Correct |
26 ms |
14980 KB |
Ok |
64 |
Correct |
24 ms |
14872 KB |
Ok |
65 |
Correct |
90 ms |
20876 KB |
Ok |
66 |
Correct |
112 ms |
21180 KB |
Ok |
67 |
Correct |
100 ms |
21240 KB |
Ok |
68 |
Correct |
83 ms |
20152 KB |
Ok |
69 |
Correct |
103 ms |
21072 KB |
Ok |
70 |
Correct |
99 ms |
20616 KB |
Ok |
71 |
Correct |
82 ms |
20140 KB |
Ok |
72 |
Correct |
82 ms |
20564 KB |
Ok |
73 |
Correct |
116 ms |
21436 KB |
Ok |
74 |
Correct |
87 ms |
20404 KB |
Ok |
75 |
Correct |
101 ms |
21124 KB |
Ok |
76 |
Correct |
103 ms |
21052 KB |
Ok |
77 |
Correct |
90 ms |
20664 KB |
Ok |
78 |
Correct |
81 ms |
20408 KB |
Ok |
79 |
Correct |
98 ms |
20996 KB |
Ok |
80 |
Correct |
254 ms |
31216 KB |
Ok |
81 |
Correct |
294 ms |
31168 KB |
Ok |
82 |
Correct |
254 ms |
29832 KB |
Ok |
83 |
Correct |
269 ms |
31300 KB |
Ok |
84 |
Correct |
241 ms |
28936 KB |
Ok |
85 |
Correct |
249 ms |
30040 KB |
Ok |
86 |
Correct |
255 ms |
30920 KB |
Ok |
87 |
Correct |
263 ms |
31144 KB |
Ok |
88 |
Correct |
264 ms |
29580 KB |
Ok |
89 |
Correct |
244 ms |
31512 KB |
Ok |
90 |
Correct |
278 ms |
30296 KB |
Ok |
91 |
Correct |
257 ms |
29716 KB |
Ok |
92 |
Correct |
270 ms |
31120 KB |
Ok |
93 |
Correct |
238 ms |
30116 KB |
Ok |
94 |
Correct |
248 ms |
31556 KB |
Ok |
95 |
Correct |
211 ms |
31304 KB |
Ok |
96 |
Correct |
311 ms |
39404 KB |
Ok |
97 |
Correct |
288 ms |
35240 KB |
Ok |
98 |
Correct |
212 ms |
34904 KB |
Ok |
99 |
Correct |
245 ms |
34288 KB |
Ok |
100 |
Correct |
258 ms |
34564 KB |
Ok |
101 |
Correct |
257 ms |
37052 KB |
Ok |
102 |
Correct |
284 ms |
35348 KB |
Ok |
103 |
Correct |
282 ms |
36632 KB |
Ok |
104 |
Correct |
302 ms |
38240 KB |
Ok |
105 |
Correct |
291 ms |
39072 KB |
Ok |
106 |
Correct |
237 ms |
38320 KB |
Ok |
107 |
Correct |
288 ms |
37848 KB |
Ok |
108 |
Correct |
308 ms |
39228 KB |
Ok |
109 |
Correct |
274 ms |
39652 KB |
Ok |
110 |
Correct |
1331 ms |
83888 KB |
Ok |
111 |
Correct |
1615 ms |
84408 KB |
Ok |
112 |
Correct |
1605 ms |
75472 KB |
Ok |
113 |
Correct |
1384 ms |
83420 KB |
Ok |
114 |
Correct |
1630 ms |
79776 KB |
Ok |
115 |
Correct |
1845 ms |
84256 KB |
Ok |
116 |
Correct |
1617 ms |
82744 KB |
Ok |
117 |
Correct |
1521 ms |
84588 KB |
Ok |
118 |
Correct |
1965 ms |
76948 KB |
Ok |
119 |
Correct |
1708 ms |
83680 KB |
Ok |
120 |
Correct |
1548 ms |
84636 KB |
Ok |
121 |
Correct |
1797 ms |
80284 KB |
Ok |
122 |
Correct |
1526 ms |
84044 KB |
Ok |
123 |
Correct |
1998 ms |
79944 KB |
Ok |
124 |
Correct |
1441 ms |
74160 KB |
Ok |
125 |
Correct |
470 ms |
68324 KB |
Ok |