//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4,avx2,fma,avx")
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define unit unsigned int
#define ld double
#define F first
#define S second
// chrono::system_clock::now().time_since_epoch().count());
using namespace std;
const int N = 4e5 + 100, IINF = 1e9 + 10, LOG = 19, K = 1 << 10;
const ll INF = 1e18 + 214;
bitset<N> usd;
vector<int> top;
void dfs(int v, vector<vector<int>> &g){
if (usd[v])
return;
usd[v] = 1;
for (auto i : g[v])
dfs(i, g);
top.push_back(v);
}
int gcd(int a, int b){
if (b == 0)
return a;
return gcd(b, a % b);
}
int nw = 0;
void fill(int v, vector<vector<int>> &g, vector<int> &pref){
if (usd[v])
return;
usd[v] = 1;
nw --;
for (auto i : g[v]){
pref[i] = pref[v] - 1;
fill(i, g, pref);
}
}
inline void solve(){
int n, m;
cin >> n >> m;
int start = -1;
if (n > m)
swap(n, m), start *= -1;
int l = n + m - 1 - gcd(n, m);
cout << l << '\n';
vector<vector<int>> g(l + 1);
for (int i = 0; i <= l; i ++){
if (i + m <= l)
g[i].push_back(i + m);
if (i - n >= 0)
g[i].push_back(i - n);
}
usd = 0;
top.clear();
for (int i = 0; i <= l; i ++){
if (usd[i])
continue;
dfs(i, g);
}
//cout << "why" << '\n';
reverse(top.begin(), top.end());
usd = 0;
vector<int> pref(l + 1, IINF);
nw = IINF;
for (auto i: top){
if (!usd[i]){
pref[i] = nw;
fill(i, g, pref);
}
}
for (int i = 1; i <= l; i ++)
cout << (pref[i] - pref[i - 1]) * start << ' ';
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin >> T;
while(T--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Ok |
2 |
Correct |
1 ms |
340 KB |
Ok |
3 |
Correct |
1 ms |
340 KB |
Ok |
4 |
Correct |
1 ms |
340 KB |
Ok |
5 |
Correct |
1 ms |
340 KB |
Ok |
6 |
Correct |
0 ms |
340 KB |
Ok |
7 |
Correct |
0 ms |
340 KB |
Ok |
8 |
Correct |
1 ms |
340 KB |
Ok |
9 |
Correct |
1 ms |
340 KB |
Ok |
10 |
Correct |
0 ms |
340 KB |
Ok |
11 |
Correct |
1 ms |
340 KB |
Ok |
12 |
Correct |
1 ms |
340 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Ok |
2 |
Correct |
0 ms |
340 KB |
Ok |
3 |
Correct |
0 ms |
340 KB |
Ok |
4 |
Correct |
1 ms |
340 KB |
Ok |
5 |
Correct |
0 ms |
340 KB |
Ok |
6 |
Correct |
3 ms |
596 KB |
Ok |
7 |
Correct |
12 ms |
1748 KB |
Ok |
8 |
Correct |
6 ms |
980 KB |
Ok |
9 |
Correct |
17 ms |
2020 KB |
Ok |
10 |
Correct |
8 ms |
1356 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Ok |
2 |
Correct |
0 ms |
340 KB |
Ok |
3 |
Correct |
0 ms |
340 KB |
Ok |
4 |
Correct |
0 ms |
340 KB |
Ok |
5 |
Correct |
0 ms |
340 KB |
Ok |
6 |
Correct |
1 ms |
340 KB |
Ok |
7 |
Correct |
1 ms |
340 KB |
Ok |
8 |
Correct |
1 ms |
340 KB |
Ok |
9 |
Correct |
1 ms |
340 KB |
Ok |
10 |
Correct |
1 ms |
340 KB |
Ok |
11 |
Correct |
0 ms |
340 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Ok |
2 |
Correct |
1 ms |
340 KB |
Ok |
3 |
Correct |
1 ms |
340 KB |
Ok |
4 |
Correct |
0 ms |
340 KB |
Ok |
5 |
Correct |
0 ms |
340 KB |
Ok |
6 |
Correct |
132 ms |
21072 KB |
Ok |
7 |
Correct |
105 ms |
22768 KB |
Ok |
8 |
Correct |
203 ms |
27476 KB |
Ok |
9 |
Correct |
166 ms |
24616 KB |
Ok |
10 |
Correct |
100 ms |
14848 KB |
Ok |
11 |
Correct |
153 ms |
26288 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Ok |
2 |
Correct |
1 ms |
340 KB |
Ok |
3 |
Correct |
1 ms |
340 KB |
Ok |
4 |
Correct |
1 ms |
340 KB |
Ok |
5 |
Correct |
1 ms |
340 KB |
Ok |
6 |
Correct |
0 ms |
340 KB |
Ok |
7 |
Correct |
0 ms |
340 KB |
Ok |
8 |
Correct |
1 ms |
340 KB |
Ok |
9 |
Correct |
1 ms |
340 KB |
Ok |
10 |
Correct |
0 ms |
340 KB |
Ok |
11 |
Correct |
1 ms |
340 KB |
Ok |
12 |
Correct |
1 ms |
340 KB |
Ok |
13 |
Correct |
0 ms |
340 KB |
Ok |
14 |
Correct |
0 ms |
340 KB |
Ok |
15 |
Correct |
0 ms |
340 KB |
Ok |
16 |
Correct |
0 ms |
340 KB |
Ok |
17 |
Correct |
0 ms |
340 KB |
Ok |
18 |
Correct |
1 ms |
340 KB |
Ok |
19 |
Correct |
1 ms |
340 KB |
Ok |
20 |
Correct |
1 ms |
340 KB |
Ok |
21 |
Correct |
1 ms |
340 KB |
Ok |
22 |
Correct |
1 ms |
340 KB |
Ok |
23 |
Correct |
0 ms |
340 KB |
Ok |
24 |
Correct |
3 ms |
596 KB |
Ok |
25 |
Correct |
3 ms |
596 KB |
Ok |
26 |
Correct |
3 ms |
596 KB |
Ok |
27 |
Correct |
2 ms |
596 KB |
Ok |
28 |
Correct |
2 ms |
596 KB |
Ok |
29 |
Correct |
3 ms |
596 KB |
Ok |
30 |
Correct |
2 ms |
468 KB |
Ok |
31 |
Correct |
3 ms |
596 KB |
Ok |
32 |
Correct |
3 ms |
596 KB |
Ok |
33 |
Correct |
3 ms |
596 KB |
Ok |
34 |
Correct |
5 ms |
980 KB |
Ok |
35 |
Correct |
5 ms |
980 KB |
Ok |
36 |
Correct |
8 ms |
980 KB |
Ok |
37 |
Correct |
5 ms |
980 KB |
Ok |
38 |
Correct |
6 ms |
980 KB |
Ok |
39 |
Correct |
6 ms |
916 KB |
Ok |
40 |
Correct |
6 ms |
980 KB |
Ok |
41 |
Correct |
6 ms |
980 KB |
Ok |
42 |
Correct |
6 ms |
980 KB |
Ok |
43 |
Correct |
6 ms |
912 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Ok |
2 |
Correct |
1 ms |
340 KB |
Ok |
3 |
Correct |
1 ms |
340 KB |
Ok |
4 |
Correct |
1 ms |
340 KB |
Ok |
5 |
Correct |
1 ms |
340 KB |
Ok |
6 |
Correct |
0 ms |
340 KB |
Ok |
7 |
Correct |
0 ms |
340 KB |
Ok |
8 |
Correct |
1 ms |
340 KB |
Ok |
9 |
Correct |
1 ms |
340 KB |
Ok |
10 |
Correct |
0 ms |
340 KB |
Ok |
11 |
Correct |
1 ms |
340 KB |
Ok |
12 |
Correct |
1 ms |
340 KB |
Ok |
13 |
Correct |
0 ms |
340 KB |
Ok |
14 |
Correct |
0 ms |
340 KB |
Ok |
15 |
Correct |
0 ms |
340 KB |
Ok |
16 |
Correct |
1 ms |
340 KB |
Ok |
17 |
Correct |
0 ms |
340 KB |
Ok |
18 |
Correct |
3 ms |
596 KB |
Ok |
19 |
Correct |
12 ms |
1748 KB |
Ok |
20 |
Correct |
6 ms |
980 KB |
Ok |
21 |
Correct |
17 ms |
2020 KB |
Ok |
22 |
Correct |
8 ms |
1356 KB |
Ok |
23 |
Correct |
0 ms |
340 KB |
Ok |
24 |
Correct |
0 ms |
340 KB |
Ok |
25 |
Correct |
0 ms |
340 KB |
Ok |
26 |
Correct |
0 ms |
340 KB |
Ok |
27 |
Correct |
0 ms |
340 KB |
Ok |
28 |
Correct |
1 ms |
340 KB |
Ok |
29 |
Correct |
1 ms |
340 KB |
Ok |
30 |
Correct |
1 ms |
340 KB |
Ok |
31 |
Correct |
1 ms |
340 KB |
Ok |
32 |
Correct |
1 ms |
340 KB |
Ok |
33 |
Correct |
0 ms |
340 KB |
Ok |
34 |
Correct |
3 ms |
596 KB |
Ok |
35 |
Correct |
3 ms |
596 KB |
Ok |
36 |
Correct |
3 ms |
596 KB |
Ok |
37 |
Correct |
2 ms |
596 KB |
Ok |
38 |
Correct |
2 ms |
596 KB |
Ok |
39 |
Correct |
3 ms |
596 KB |
Ok |
40 |
Correct |
2 ms |
468 KB |
Ok |
41 |
Correct |
3 ms |
596 KB |
Ok |
42 |
Correct |
3 ms |
596 KB |
Ok |
43 |
Correct |
3 ms |
596 KB |
Ok |
44 |
Correct |
5 ms |
980 KB |
Ok |
45 |
Correct |
5 ms |
980 KB |
Ok |
46 |
Correct |
8 ms |
980 KB |
Ok |
47 |
Correct |
5 ms |
980 KB |
Ok |
48 |
Correct |
6 ms |
980 KB |
Ok |
49 |
Correct |
6 ms |
916 KB |
Ok |
50 |
Correct |
6 ms |
980 KB |
Ok |
51 |
Correct |
6 ms |
980 KB |
Ok |
52 |
Correct |
6 ms |
980 KB |
Ok |
53 |
Correct |
6 ms |
912 KB |
Ok |
54 |
Correct |
89 ms |
8268 KB |
Ok |
55 |
Correct |
112 ms |
8480 KB |
Ok |
56 |
Correct |
107 ms |
8556 KB |
Ok |
57 |
Correct |
73 ms |
7464 KB |
Ok |
58 |
Correct |
94 ms |
8212 KB |
Ok |
59 |
Correct |
93 ms |
7900 KB |
Ok |
60 |
Correct |
72 ms |
7424 KB |
Ok |
61 |
Correct |
86 ms |
7884 KB |
Ok |
62 |
Correct |
107 ms |
8748 KB |
Ok |
63 |
Correct |
81 ms |
7692 KB |
Ok |
64 |
Correct |
112 ms |
8876 KB |
Ok |
65 |
Correct |
95 ms |
8364 KB |
Ok |
66 |
Correct |
88 ms |
7564 KB |
Ok |
67 |
Correct |
73 ms |
7696 KB |
Ok |
68 |
Correct |
88 ms |
8440 KB |
Ok |
69 |
Correct |
255 ms |
17576 KB |
Ok |
70 |
Correct |
262 ms |
17856 KB |
Ok |
71 |
Correct |
245 ms |
17908 KB |
Ok |
72 |
Correct |
231 ms |
17352 KB |
Ok |
73 |
Correct |
344 ms |
17724 KB |
Ok |
74 |
Correct |
277 ms |
17940 KB |
Ok |
75 |
Correct |
280 ms |
17420 KB |
Ok |
76 |
Correct |
246 ms |
17528 KB |
Ok |
77 |
Correct |
292 ms |
17720 KB |
Ok |
78 |
Correct |
255 ms |
17316 KB |
Ok |
79 |
Correct |
314 ms |
17916 KB |
Ok |
80 |
Correct |
317 ms |
17664 KB |
Ok |
81 |
Correct |
253 ms |
17708 KB |
Ok |
82 |
Correct |
240 ms |
17752 KB |
Ok |
83 |
Correct |
326 ms |
17800 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Ok |
2 |
Correct |
1 ms |
340 KB |
Ok |
3 |
Correct |
1 ms |
340 KB |
Ok |
4 |
Correct |
1 ms |
340 KB |
Ok |
5 |
Correct |
1 ms |
340 KB |
Ok |
6 |
Correct |
0 ms |
340 KB |
Ok |
7 |
Correct |
0 ms |
340 KB |
Ok |
8 |
Correct |
1 ms |
340 KB |
Ok |
9 |
Correct |
1 ms |
340 KB |
Ok |
10 |
Correct |
0 ms |
340 KB |
Ok |
11 |
Correct |
1 ms |
340 KB |
Ok |
12 |
Correct |
1 ms |
340 KB |
Ok |
13 |
Correct |
0 ms |
340 KB |
Ok |
14 |
Correct |
0 ms |
340 KB |
Ok |
15 |
Correct |
0 ms |
340 KB |
Ok |
16 |
Correct |
1 ms |
340 KB |
Ok |
17 |
Correct |
0 ms |
340 KB |
Ok |
18 |
Correct |
3 ms |
596 KB |
Ok |
19 |
Correct |
12 ms |
1748 KB |
Ok |
20 |
Correct |
6 ms |
980 KB |
Ok |
21 |
Correct |
17 ms |
2020 KB |
Ok |
22 |
Correct |
8 ms |
1356 KB |
Ok |
23 |
Correct |
0 ms |
340 KB |
Ok |
24 |
Correct |
0 ms |
340 KB |
Ok |
25 |
Correct |
0 ms |
340 KB |
Ok |
26 |
Correct |
0 ms |
340 KB |
Ok |
27 |
Correct |
0 ms |
340 KB |
Ok |
28 |
Correct |
1 ms |
340 KB |
Ok |
29 |
Correct |
1 ms |
340 KB |
Ok |
30 |
Correct |
1 ms |
340 KB |
Ok |
31 |
Correct |
1 ms |
340 KB |
Ok |
32 |
Correct |
1 ms |
340 KB |
Ok |
33 |
Correct |
0 ms |
340 KB |
Ok |
34 |
Correct |
1 ms |
340 KB |
Ok |
35 |
Correct |
1 ms |
340 KB |
Ok |
36 |
Correct |
1 ms |
340 KB |
Ok |
37 |
Correct |
0 ms |
340 KB |
Ok |
38 |
Correct |
0 ms |
340 KB |
Ok |
39 |
Correct |
132 ms |
21072 KB |
Ok |
40 |
Correct |
105 ms |
22768 KB |
Ok |
41 |
Correct |
203 ms |
27476 KB |
Ok |
42 |
Correct |
166 ms |
24616 KB |
Ok |
43 |
Correct |
100 ms |
14848 KB |
Ok |
44 |
Correct |
153 ms |
26288 KB |
Ok |
45 |
Correct |
3 ms |
596 KB |
Ok |
46 |
Correct |
3 ms |
596 KB |
Ok |
47 |
Correct |
3 ms |
596 KB |
Ok |
48 |
Correct |
2 ms |
596 KB |
Ok |
49 |
Correct |
2 ms |
596 KB |
Ok |
50 |
Correct |
3 ms |
596 KB |
Ok |
51 |
Correct |
2 ms |
468 KB |
Ok |
52 |
Correct |
3 ms |
596 KB |
Ok |
53 |
Correct |
3 ms |
596 KB |
Ok |
54 |
Correct |
3 ms |
596 KB |
Ok |
55 |
Correct |
5 ms |
980 KB |
Ok |
56 |
Correct |
5 ms |
980 KB |
Ok |
57 |
Correct |
8 ms |
980 KB |
Ok |
58 |
Correct |
5 ms |
980 KB |
Ok |
59 |
Correct |
6 ms |
980 KB |
Ok |
60 |
Correct |
6 ms |
916 KB |
Ok |
61 |
Correct |
6 ms |
980 KB |
Ok |
62 |
Correct |
6 ms |
980 KB |
Ok |
63 |
Correct |
6 ms |
980 KB |
Ok |
64 |
Correct |
6 ms |
912 KB |
Ok |
65 |
Correct |
89 ms |
8268 KB |
Ok |
66 |
Correct |
112 ms |
8480 KB |
Ok |
67 |
Correct |
107 ms |
8556 KB |
Ok |
68 |
Correct |
73 ms |
7464 KB |
Ok |
69 |
Correct |
94 ms |
8212 KB |
Ok |
70 |
Correct |
93 ms |
7900 KB |
Ok |
71 |
Correct |
72 ms |
7424 KB |
Ok |
72 |
Correct |
86 ms |
7884 KB |
Ok |
73 |
Correct |
107 ms |
8748 KB |
Ok |
74 |
Correct |
81 ms |
7692 KB |
Ok |
75 |
Correct |
112 ms |
8876 KB |
Ok |
76 |
Correct |
95 ms |
8364 KB |
Ok |
77 |
Correct |
88 ms |
7564 KB |
Ok |
78 |
Correct |
73 ms |
7696 KB |
Ok |
79 |
Correct |
88 ms |
8440 KB |
Ok |
80 |
Correct |
255 ms |
17576 KB |
Ok |
81 |
Correct |
262 ms |
17856 KB |
Ok |
82 |
Correct |
245 ms |
17908 KB |
Ok |
83 |
Correct |
231 ms |
17352 KB |
Ok |
84 |
Correct |
344 ms |
17724 KB |
Ok |
85 |
Correct |
277 ms |
17940 KB |
Ok |
86 |
Correct |
280 ms |
17420 KB |
Ok |
87 |
Correct |
246 ms |
17528 KB |
Ok |
88 |
Correct |
292 ms |
17720 KB |
Ok |
89 |
Correct |
255 ms |
17316 KB |
Ok |
90 |
Correct |
314 ms |
17916 KB |
Ok |
91 |
Correct |
317 ms |
17664 KB |
Ok |
92 |
Correct |
253 ms |
17708 KB |
Ok |
93 |
Correct |
240 ms |
17752 KB |
Ok |
94 |
Correct |
326 ms |
17800 KB |
Ok |
95 |
Correct |
239 ms |
19708 KB |
Ok |
96 |
Correct |
344 ms |
29552 KB |
Ok |
97 |
Correct |
353 ms |
24376 KB |
Ok |
98 |
Correct |
226 ms |
21456 KB |
Ok |
99 |
Correct |
276 ms |
22264 KB |
Ok |
100 |
Correct |
317 ms |
23928 KB |
Ok |
101 |
Correct |
289 ms |
25372 KB |
Ok |
102 |
Correct |
300 ms |
25932 KB |
Ok |
103 |
Correct |
355 ms |
26852 KB |
Ok |
104 |
Correct |
353 ms |
29228 KB |
Ok |
105 |
Correct |
343 ms |
29920 KB |
Ok |
106 |
Correct |
294 ms |
27144 KB |
Ok |
107 |
Correct |
301 ms |
29512 KB |
Ok |
108 |
Correct |
375 ms |
30180 KB |
Ok |
109 |
Correct |
341 ms |
28612 KB |
Ok |
110 |
Correct |
1791 ms |
70892 KB |
Ok |
111 |
Execution timed out |
2068 ms |
71896 KB |
Time limit exceeded |
112 |
Halted |
0 ms |
0 KB |
- |