#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 5e5+777;
const int MOD = 1e9+7;
const bool I = 1;
int n, m;
bool used[N];
vector<int> ts, ans, g[N];
void dfs(int v){
used[v] = 1;
for(auto to : g[v]){
if(!used[to]){
dfs(to);
}
}
ts.pb(v);
}
void check(int R){
memset(used,0,sizeof(used));
for(int i = 0; i <= R; ++i){
if(i - n >= 0) g[i].pb(i-n);
if(i + m <= R) g[i].pb(i+m);
}
for(int i = 0; i <= R; ++i){
if(!used[i]) dfs(i);
}
reverse(all(ts));
vector<int> pref(R+1, 0);
ans.clear();
int cnt = 0;
// cerr << "TS\n";
for(int x : ts){
// cerr << x << ' ';
pref[x] = cnt++;
}
// cerr << '\n';
ts.clear();
for(int i = 1; i <= R; ++i){
ans.pb(pref[i] - pref[i-1]);
}
}
int main(){auto solve=[&](){
cin >> n >> m;
int len = n + m - 1 - __gcd(n, m);
check(len);
cout << sz(ans) << '\n';
for(auto it : ans){
cout << it << ' ';
}cout << '\n';
for(int i = 0; i <= len; ++i){
g[i].clear();
}
};NFS;int T=1;if(I)cin>>T;while(T--)solve();}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12492 KB |
Ok |
2 |
Correct |
6 ms |
12492 KB |
Ok |
3 |
Correct |
7 ms |
12492 KB |
Ok |
4 |
Correct |
10 ms |
12492 KB |
Ok |
5 |
Correct |
7 ms |
12492 KB |
Ok |
6 |
Correct |
7 ms |
12492 KB |
Ok |
7 |
Correct |
8 ms |
12620 KB |
Ok |
8 |
Correct |
7 ms |
12492 KB |
Ok |
9 |
Correct |
7 ms |
12492 KB |
Ok |
10 |
Correct |
7 ms |
12492 KB |
Ok |
11 |
Correct |
8 ms |
12492 KB |
Ok |
12 |
Correct |
6 ms |
12492 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12492 KB |
Ok |
2 |
Correct |
7 ms |
12492 KB |
Ok |
3 |
Correct |
6 ms |
12492 KB |
Ok |
4 |
Correct |
6 ms |
12492 KB |
Ok |
5 |
Correct |
10 ms |
12492 KB |
Ok |
6 |
Correct |
9 ms |
12748 KB |
Ok |
7 |
Correct |
14 ms |
13524 KB |
Ok |
8 |
Correct |
10 ms |
13004 KB |
Ok |
9 |
Correct |
20 ms |
13692 KB |
Ok |
10 |
Correct |
15 ms |
13120 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12492 KB |
Ok |
2 |
Correct |
6 ms |
12492 KB |
Ok |
3 |
Correct |
8 ms |
12472 KB |
Ok |
4 |
Correct |
7 ms |
12524 KB |
Ok |
5 |
Correct |
6 ms |
12492 KB |
Ok |
6 |
Correct |
8 ms |
12544 KB |
Ok |
7 |
Correct |
7 ms |
12464 KB |
Ok |
8 |
Correct |
7 ms |
12452 KB |
Ok |
9 |
Correct |
6 ms |
12492 KB |
Ok |
10 |
Correct |
7 ms |
12464 KB |
Ok |
11 |
Correct |
7 ms |
12488 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12492 KB |
Ok |
2 |
Correct |
7 ms |
12464 KB |
Ok |
3 |
Correct |
6 ms |
12492 KB |
Ok |
4 |
Correct |
7 ms |
12532 KB |
Ok |
5 |
Correct |
7 ms |
12444 KB |
Ok |
6 |
Correct |
90 ms |
27588 KB |
Ok |
7 |
Correct |
78 ms |
27272 KB |
Ok |
8 |
Correct |
140 ms |
30288 KB |
Ok |
9 |
Correct |
110 ms |
27688 KB |
Ok |
10 |
Correct |
70 ms |
22964 KB |
Ok |
11 |
Correct |
111 ms |
31636 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12492 KB |
Ok |
2 |
Correct |
6 ms |
12492 KB |
Ok |
3 |
Correct |
7 ms |
12492 KB |
Ok |
4 |
Correct |
10 ms |
12492 KB |
Ok |
5 |
Correct |
7 ms |
12492 KB |
Ok |
6 |
Correct |
7 ms |
12492 KB |
Ok |
7 |
Correct |
8 ms |
12620 KB |
Ok |
8 |
Correct |
7 ms |
12492 KB |
Ok |
9 |
Correct |
7 ms |
12492 KB |
Ok |
10 |
Correct |
7 ms |
12492 KB |
Ok |
11 |
Correct |
8 ms |
12492 KB |
Ok |
12 |
Correct |
6 ms |
12492 KB |
Ok |
13 |
Correct |
6 ms |
12492 KB |
Ok |
14 |
Correct |
6 ms |
12492 KB |
Ok |
15 |
Correct |
8 ms |
12472 KB |
Ok |
16 |
Correct |
7 ms |
12524 KB |
Ok |
17 |
Correct |
6 ms |
12492 KB |
Ok |
18 |
Correct |
8 ms |
12544 KB |
Ok |
19 |
Correct |
7 ms |
12464 KB |
Ok |
20 |
Correct |
7 ms |
12452 KB |
Ok |
21 |
Correct |
6 ms |
12492 KB |
Ok |
22 |
Correct |
7 ms |
12464 KB |
Ok |
23 |
Correct |
7 ms |
12488 KB |
Ok |
24 |
Correct |
9 ms |
12748 KB |
Ok |
25 |
Correct |
8 ms |
12724 KB |
Ok |
26 |
Correct |
8 ms |
12748 KB |
Ok |
27 |
Correct |
8 ms |
12748 KB |
Ok |
28 |
Correct |
8 ms |
12620 KB |
Ok |
29 |
Correct |
9 ms |
12620 KB |
Ok |
30 |
Correct |
9 ms |
12620 KB |
Ok |
31 |
Correct |
10 ms |
12748 KB |
Ok |
32 |
Correct |
11 ms |
12696 KB |
Ok |
33 |
Correct |
9 ms |
12748 KB |
Ok |
34 |
Correct |
12 ms |
12876 KB |
Ok |
35 |
Correct |
9 ms |
12876 KB |
Ok |
36 |
Correct |
9 ms |
13004 KB |
Ok |
37 |
Correct |
10 ms |
12972 KB |
Ok |
38 |
Correct |
10 ms |
12972 KB |
Ok |
39 |
Correct |
9 ms |
12852 KB |
Ok |
40 |
Correct |
10 ms |
12976 KB |
Ok |
41 |
Correct |
10 ms |
12876 KB |
Ok |
42 |
Correct |
12 ms |
13008 KB |
Ok |
43 |
Correct |
9 ms |
12984 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12492 KB |
Ok |
2 |
Correct |
6 ms |
12492 KB |
Ok |
3 |
Correct |
7 ms |
12492 KB |
Ok |
4 |
Correct |
10 ms |
12492 KB |
Ok |
5 |
Correct |
7 ms |
12492 KB |
Ok |
6 |
Correct |
7 ms |
12492 KB |
Ok |
7 |
Correct |
8 ms |
12620 KB |
Ok |
8 |
Correct |
7 ms |
12492 KB |
Ok |
9 |
Correct |
7 ms |
12492 KB |
Ok |
10 |
Correct |
7 ms |
12492 KB |
Ok |
11 |
Correct |
8 ms |
12492 KB |
Ok |
12 |
Correct |
6 ms |
12492 KB |
Ok |
13 |
Correct |
6 ms |
12492 KB |
Ok |
14 |
Correct |
7 ms |
12492 KB |
Ok |
15 |
Correct |
6 ms |
12492 KB |
Ok |
16 |
Correct |
6 ms |
12492 KB |
Ok |
17 |
Correct |
10 ms |
12492 KB |
Ok |
18 |
Correct |
9 ms |
12748 KB |
Ok |
19 |
Correct |
14 ms |
13524 KB |
Ok |
20 |
Correct |
10 ms |
13004 KB |
Ok |
21 |
Correct |
20 ms |
13692 KB |
Ok |
22 |
Correct |
15 ms |
13120 KB |
Ok |
23 |
Correct |
6 ms |
12492 KB |
Ok |
24 |
Correct |
6 ms |
12492 KB |
Ok |
25 |
Correct |
8 ms |
12472 KB |
Ok |
26 |
Correct |
7 ms |
12524 KB |
Ok |
27 |
Correct |
6 ms |
12492 KB |
Ok |
28 |
Correct |
8 ms |
12544 KB |
Ok |
29 |
Correct |
7 ms |
12464 KB |
Ok |
30 |
Correct |
7 ms |
12452 KB |
Ok |
31 |
Correct |
6 ms |
12492 KB |
Ok |
32 |
Correct |
7 ms |
12464 KB |
Ok |
33 |
Correct |
7 ms |
12488 KB |
Ok |
34 |
Correct |
9 ms |
12748 KB |
Ok |
35 |
Correct |
8 ms |
12724 KB |
Ok |
36 |
Correct |
8 ms |
12748 KB |
Ok |
37 |
Correct |
8 ms |
12748 KB |
Ok |
38 |
Correct |
8 ms |
12620 KB |
Ok |
39 |
Correct |
9 ms |
12620 KB |
Ok |
40 |
Correct |
9 ms |
12620 KB |
Ok |
41 |
Correct |
10 ms |
12748 KB |
Ok |
42 |
Correct |
11 ms |
12696 KB |
Ok |
43 |
Correct |
9 ms |
12748 KB |
Ok |
44 |
Correct |
12 ms |
12876 KB |
Ok |
45 |
Correct |
9 ms |
12876 KB |
Ok |
46 |
Correct |
9 ms |
13004 KB |
Ok |
47 |
Correct |
10 ms |
12972 KB |
Ok |
48 |
Correct |
10 ms |
12972 KB |
Ok |
49 |
Correct |
9 ms |
12852 KB |
Ok |
50 |
Correct |
10 ms |
12976 KB |
Ok |
51 |
Correct |
10 ms |
12876 KB |
Ok |
52 |
Correct |
12 ms |
13008 KB |
Ok |
53 |
Correct |
9 ms |
12984 KB |
Ok |
54 |
Correct |
71 ms |
18548 KB |
Ok |
55 |
Correct |
74 ms |
19068 KB |
Ok |
56 |
Correct |
75 ms |
19028 KB |
Ok |
57 |
Correct |
62 ms |
17944 KB |
Ok |
58 |
Correct |
69 ms |
18852 KB |
Ok |
59 |
Correct |
70 ms |
18456 KB |
Ok |
60 |
Correct |
60 ms |
17960 KB |
Ok |
61 |
Correct |
58 ms |
18328 KB |
Ok |
62 |
Correct |
84 ms |
19196 KB |
Ok |
63 |
Correct |
63 ms |
18248 KB |
Ok |
64 |
Correct |
74 ms |
18912 KB |
Ok |
65 |
Correct |
97 ms |
18844 KB |
Ok |
66 |
Correct |
63 ms |
18460 KB |
Ok |
67 |
Correct |
59 ms |
18276 KB |
Ok |
68 |
Correct |
72 ms |
18676 KB |
Ok |
69 |
Correct |
161 ms |
25736 KB |
Ok |
70 |
Correct |
189 ms |
25860 KB |
Ok |
71 |
Correct |
137 ms |
24368 KB |
Ok |
72 |
Correct |
156 ms |
25728 KB |
Ok |
73 |
Correct |
150 ms |
24692 KB |
Ok |
74 |
Correct |
166 ms |
25180 KB |
Ok |
75 |
Correct |
180 ms |
25476 KB |
Ok |
76 |
Correct |
170 ms |
25784 KB |
Ok |
77 |
Correct |
148 ms |
25088 KB |
Ok |
78 |
Correct |
156 ms |
25788 KB |
Ok |
79 |
Correct |
168 ms |
25424 KB |
Ok |
80 |
Correct |
137 ms |
24468 KB |
Ok |
81 |
Correct |
159 ms |
25924 KB |
Ok |
82 |
Correct |
173 ms |
25264 KB |
Ok |
83 |
Correct |
158 ms |
25820 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12492 KB |
Ok |
2 |
Correct |
6 ms |
12492 KB |
Ok |
3 |
Correct |
7 ms |
12492 KB |
Ok |
4 |
Correct |
10 ms |
12492 KB |
Ok |
5 |
Correct |
7 ms |
12492 KB |
Ok |
6 |
Correct |
7 ms |
12492 KB |
Ok |
7 |
Correct |
8 ms |
12620 KB |
Ok |
8 |
Correct |
7 ms |
12492 KB |
Ok |
9 |
Correct |
7 ms |
12492 KB |
Ok |
10 |
Correct |
7 ms |
12492 KB |
Ok |
11 |
Correct |
8 ms |
12492 KB |
Ok |
12 |
Correct |
6 ms |
12492 KB |
Ok |
13 |
Correct |
6 ms |
12492 KB |
Ok |
14 |
Correct |
7 ms |
12492 KB |
Ok |
15 |
Correct |
6 ms |
12492 KB |
Ok |
16 |
Correct |
6 ms |
12492 KB |
Ok |
17 |
Correct |
10 ms |
12492 KB |
Ok |
18 |
Correct |
9 ms |
12748 KB |
Ok |
19 |
Correct |
14 ms |
13524 KB |
Ok |
20 |
Correct |
10 ms |
13004 KB |
Ok |
21 |
Correct |
20 ms |
13692 KB |
Ok |
22 |
Correct |
15 ms |
13120 KB |
Ok |
23 |
Correct |
6 ms |
12492 KB |
Ok |
24 |
Correct |
6 ms |
12492 KB |
Ok |
25 |
Correct |
8 ms |
12472 KB |
Ok |
26 |
Correct |
7 ms |
12524 KB |
Ok |
27 |
Correct |
6 ms |
12492 KB |
Ok |
28 |
Correct |
8 ms |
12544 KB |
Ok |
29 |
Correct |
7 ms |
12464 KB |
Ok |
30 |
Correct |
7 ms |
12452 KB |
Ok |
31 |
Correct |
6 ms |
12492 KB |
Ok |
32 |
Correct |
7 ms |
12464 KB |
Ok |
33 |
Correct |
7 ms |
12488 KB |
Ok |
34 |
Correct |
7 ms |
12492 KB |
Ok |
35 |
Correct |
7 ms |
12464 KB |
Ok |
36 |
Correct |
6 ms |
12492 KB |
Ok |
37 |
Correct |
7 ms |
12532 KB |
Ok |
38 |
Correct |
7 ms |
12444 KB |
Ok |
39 |
Correct |
90 ms |
27588 KB |
Ok |
40 |
Correct |
78 ms |
27272 KB |
Ok |
41 |
Correct |
140 ms |
30288 KB |
Ok |
42 |
Correct |
110 ms |
27688 KB |
Ok |
43 |
Correct |
70 ms |
22964 KB |
Ok |
44 |
Correct |
111 ms |
31636 KB |
Ok |
45 |
Correct |
9 ms |
12748 KB |
Ok |
46 |
Correct |
8 ms |
12724 KB |
Ok |
47 |
Correct |
8 ms |
12748 KB |
Ok |
48 |
Correct |
8 ms |
12748 KB |
Ok |
49 |
Correct |
8 ms |
12620 KB |
Ok |
50 |
Correct |
9 ms |
12620 KB |
Ok |
51 |
Correct |
9 ms |
12620 KB |
Ok |
52 |
Correct |
10 ms |
12748 KB |
Ok |
53 |
Correct |
11 ms |
12696 KB |
Ok |
54 |
Correct |
9 ms |
12748 KB |
Ok |
55 |
Correct |
12 ms |
12876 KB |
Ok |
56 |
Correct |
9 ms |
12876 KB |
Ok |
57 |
Correct |
9 ms |
13004 KB |
Ok |
58 |
Correct |
10 ms |
12972 KB |
Ok |
59 |
Correct |
10 ms |
12972 KB |
Ok |
60 |
Correct |
9 ms |
12852 KB |
Ok |
61 |
Correct |
10 ms |
12976 KB |
Ok |
62 |
Correct |
10 ms |
12876 KB |
Ok |
63 |
Correct |
12 ms |
13008 KB |
Ok |
64 |
Correct |
9 ms |
12984 KB |
Ok |
65 |
Correct |
71 ms |
18548 KB |
Ok |
66 |
Correct |
74 ms |
19068 KB |
Ok |
67 |
Correct |
75 ms |
19028 KB |
Ok |
68 |
Correct |
62 ms |
17944 KB |
Ok |
69 |
Correct |
69 ms |
18852 KB |
Ok |
70 |
Correct |
70 ms |
18456 KB |
Ok |
71 |
Correct |
60 ms |
17960 KB |
Ok |
72 |
Correct |
58 ms |
18328 KB |
Ok |
73 |
Correct |
84 ms |
19196 KB |
Ok |
74 |
Correct |
63 ms |
18248 KB |
Ok |
75 |
Correct |
74 ms |
18912 KB |
Ok |
76 |
Correct |
97 ms |
18844 KB |
Ok |
77 |
Correct |
63 ms |
18460 KB |
Ok |
78 |
Correct |
59 ms |
18276 KB |
Ok |
79 |
Correct |
72 ms |
18676 KB |
Ok |
80 |
Correct |
161 ms |
25736 KB |
Ok |
81 |
Correct |
189 ms |
25860 KB |
Ok |
82 |
Correct |
137 ms |
24368 KB |
Ok |
83 |
Correct |
156 ms |
25728 KB |
Ok |
84 |
Correct |
150 ms |
24692 KB |
Ok |
85 |
Correct |
166 ms |
25180 KB |
Ok |
86 |
Correct |
180 ms |
25476 KB |
Ok |
87 |
Correct |
170 ms |
25784 KB |
Ok |
88 |
Correct |
148 ms |
25088 KB |
Ok |
89 |
Correct |
156 ms |
25788 KB |
Ok |
90 |
Correct |
168 ms |
25424 KB |
Ok |
91 |
Correct |
137 ms |
24468 KB |
Ok |
92 |
Correct |
159 ms |
25924 KB |
Ok |
93 |
Correct |
173 ms |
25264 KB |
Ok |
94 |
Correct |
158 ms |
25820 KB |
Ok |
95 |
Correct |
168 ms |
28376 KB |
Ok |
96 |
Correct |
234 ms |
35540 KB |
Ok |
97 |
Correct |
226 ms |
32224 KB |
Ok |
98 |
Correct |
171 ms |
31360 KB |
Ok |
99 |
Correct |
210 ms |
31264 KB |
Ok |
100 |
Correct |
218 ms |
31764 KB |
Ok |
101 |
Correct |
215 ms |
33796 KB |
Ok |
102 |
Correct |
196 ms |
32284 KB |
Ok |
103 |
Correct |
205 ms |
33524 KB |
Ok |
104 |
Correct |
236 ms |
34924 KB |
Ok |
105 |
Correct |
227 ms |
35044 KB |
Ok |
106 |
Correct |
187 ms |
34752 KB |
Ok |
107 |
Correct |
227 ms |
34692 KB |
Ok |
108 |
Correct |
253 ms |
35848 KB |
Ok |
109 |
Correct |
211 ms |
36076 KB |
Ok |
110 |
Correct |
937 ms |
67664 KB |
Ok |
111 |
Correct |
1107 ms |
68552 KB |
Ok |
112 |
Correct |
1098 ms |
64520 KB |
Ok |
113 |
Correct |
919 ms |
67572 KB |
Ok |
114 |
Correct |
1074 ms |
64044 KB |
Ok |
115 |
Correct |
1168 ms |
68692 KB |
Ok |
116 |
Correct |
1099 ms |
68248 KB |
Ok |
117 |
Correct |
1008 ms |
68256 KB |
Ok |
118 |
Correct |
1080 ms |
63064 KB |
Ok |
119 |
Correct |
1063 ms |
67588 KB |
Ok |
120 |
Correct |
1051 ms |
68564 KB |
Ok |
121 |
Correct |
1006 ms |
66176 KB |
Ok |
122 |
Correct |
993 ms |
68256 KB |
Ok |
123 |
Correct |
1148 ms |
66668 KB |
Ok |
124 |
Correct |
962 ms |
64228 KB |
Ok |
125 |
Correct |
377 ms |
51668 KB |
Ok |