#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 4e6+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
bool used[N];
vector<int> order;
int md;
void dfs(int u){
used[u] = true;
if(u-n >= 0 && !used[u-n])dfs(u-n);
if(u+m <= md && !used[u+m])dfs(u+m);
order.pb(u);
}
bool check(int mid){
int i;
md = mid;
order.clear();
memset(used, 0, sizeof(used));
for(i=0;i<=mid;i++)if(!used[i])dfs(i);
for(i=0;i<=mid;i++)a[order[i]] = i;
for(i=0;i<=n;i++){
if(i-n >= 0){
if(i==n){
if(a[i]>=0)return false;
}else if(a[i]-a[i-n-1] >=0)return false;
}else {
if(i==m){
if(a[i]>=0)return false;
}else if(a[i]-a[i-m-1] >=0)return false;
}
}return true;
}
void solve(int test_case){
int i, j;
cin >> n >> m;
int l = n+m-1-__gcd(n,m);
check(l);
cout << l << '\n';
for(i=1;i<=l;i++){
cout << -(a[i]-a[i-1]) << ' ';
}cout << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 1
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
sequence.cpp: In function 'void solve(long long int)':
sequence.cpp:45:9: warning: unused variable 'j' [-Wunused-variable]
45 | int i, j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
4 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
4 ms |
4204 KB |
Ok |
7 |
Correct |
4 ms |
4204 KB |
Ok |
8 |
Correct |
4 ms |
4204 KB |
Ok |
9 |
Correct |
4 ms |
4204 KB |
Ok |
10 |
Correct |
4 ms |
4204 KB |
Ok |
11 |
Correct |
4 ms |
4204 KB |
Ok |
12 |
Correct |
4 ms |
4204 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
4 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
6 ms |
4332 KB |
Ok |
7 |
Correct |
13 ms |
5100 KB |
Ok |
8 |
Correct |
9 ms |
4588 KB |
Ok |
9 |
Correct |
16 ms |
5228 KB |
Ok |
10 |
Correct |
10 ms |
4716 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
6 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
4 ms |
4332 KB |
Ok |
7 |
Correct |
4 ms |
4204 KB |
Ok |
8 |
Correct |
4 ms |
4204 KB |
Ok |
9 |
Correct |
4 ms |
4204 KB |
Ok |
10 |
Correct |
4 ms |
4204 KB |
Ok |
11 |
Correct |
4 ms |
4204 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
4 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
93 ms |
15332 KB |
Ok |
7 |
Correct |
78 ms |
14200 KB |
Ok |
8 |
Correct |
141 ms |
17252 KB |
Ok |
9 |
Correct |
128 ms |
15460 KB |
Ok |
10 |
Correct |
73 ms |
11880 KB |
Ok |
11 |
Correct |
114 ms |
18532 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
4 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
4 ms |
4204 KB |
Ok |
7 |
Correct |
4 ms |
4204 KB |
Ok |
8 |
Correct |
4 ms |
4204 KB |
Ok |
9 |
Correct |
4 ms |
4204 KB |
Ok |
10 |
Correct |
4 ms |
4204 KB |
Ok |
11 |
Correct |
4 ms |
4204 KB |
Ok |
12 |
Correct |
4 ms |
4204 KB |
Ok |
13 |
Correct |
3 ms |
4204 KB |
Ok |
14 |
Correct |
4 ms |
4204 KB |
Ok |
15 |
Correct |
6 ms |
4204 KB |
Ok |
16 |
Correct |
4 ms |
4204 KB |
Ok |
17 |
Correct |
4 ms |
4204 KB |
Ok |
18 |
Correct |
4 ms |
4332 KB |
Ok |
19 |
Correct |
4 ms |
4204 KB |
Ok |
20 |
Correct |
4 ms |
4204 KB |
Ok |
21 |
Correct |
4 ms |
4204 KB |
Ok |
22 |
Correct |
4 ms |
4204 KB |
Ok |
23 |
Correct |
4 ms |
4204 KB |
Ok |
24 |
Correct |
6 ms |
4332 KB |
Ok |
25 |
Correct |
6 ms |
4460 KB |
Ok |
26 |
Correct |
6 ms |
4460 KB |
Ok |
27 |
Correct |
6 ms |
4332 KB |
Ok |
28 |
Correct |
6 ms |
4332 KB |
Ok |
29 |
Correct |
6 ms |
4332 KB |
Ok |
30 |
Correct |
6 ms |
4332 KB |
Ok |
31 |
Correct |
7 ms |
4460 KB |
Ok |
32 |
Correct |
6 ms |
4332 KB |
Ok |
33 |
Correct |
6 ms |
4332 KB |
Ok |
34 |
Correct |
9 ms |
4588 KB |
Ok |
35 |
Correct |
8 ms |
4588 KB |
Ok |
36 |
Correct |
8 ms |
4588 KB |
Ok |
37 |
Correct |
8 ms |
4588 KB |
Ok |
38 |
Correct |
8 ms |
4588 KB |
Ok |
39 |
Correct |
8 ms |
4588 KB |
Ok |
40 |
Correct |
8 ms |
4588 KB |
Ok |
41 |
Correct |
8 ms |
4588 KB |
Ok |
42 |
Correct |
8 ms |
4588 KB |
Ok |
43 |
Correct |
8 ms |
4588 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
4 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
4 ms |
4204 KB |
Ok |
7 |
Correct |
4 ms |
4204 KB |
Ok |
8 |
Correct |
4 ms |
4204 KB |
Ok |
9 |
Correct |
4 ms |
4204 KB |
Ok |
10 |
Correct |
4 ms |
4204 KB |
Ok |
11 |
Correct |
4 ms |
4204 KB |
Ok |
12 |
Correct |
4 ms |
4204 KB |
Ok |
13 |
Correct |
4 ms |
4204 KB |
Ok |
14 |
Correct |
4 ms |
4204 KB |
Ok |
15 |
Correct |
4 ms |
4204 KB |
Ok |
16 |
Correct |
4 ms |
4204 KB |
Ok |
17 |
Correct |
4 ms |
4204 KB |
Ok |
18 |
Correct |
6 ms |
4332 KB |
Ok |
19 |
Correct |
13 ms |
5100 KB |
Ok |
20 |
Correct |
9 ms |
4588 KB |
Ok |
21 |
Correct |
16 ms |
5228 KB |
Ok |
22 |
Correct |
10 ms |
4716 KB |
Ok |
23 |
Correct |
3 ms |
4204 KB |
Ok |
24 |
Correct |
4 ms |
4204 KB |
Ok |
25 |
Correct |
6 ms |
4204 KB |
Ok |
26 |
Correct |
4 ms |
4204 KB |
Ok |
27 |
Correct |
4 ms |
4204 KB |
Ok |
28 |
Correct |
4 ms |
4332 KB |
Ok |
29 |
Correct |
4 ms |
4204 KB |
Ok |
30 |
Correct |
4 ms |
4204 KB |
Ok |
31 |
Correct |
4 ms |
4204 KB |
Ok |
32 |
Correct |
4 ms |
4204 KB |
Ok |
33 |
Correct |
4 ms |
4204 KB |
Ok |
34 |
Correct |
6 ms |
4332 KB |
Ok |
35 |
Correct |
6 ms |
4460 KB |
Ok |
36 |
Correct |
6 ms |
4460 KB |
Ok |
37 |
Correct |
6 ms |
4332 KB |
Ok |
38 |
Correct |
6 ms |
4332 KB |
Ok |
39 |
Correct |
6 ms |
4332 KB |
Ok |
40 |
Correct |
6 ms |
4332 KB |
Ok |
41 |
Correct |
7 ms |
4460 KB |
Ok |
42 |
Correct |
6 ms |
4332 KB |
Ok |
43 |
Correct |
6 ms |
4332 KB |
Ok |
44 |
Correct |
9 ms |
4588 KB |
Ok |
45 |
Correct |
8 ms |
4588 KB |
Ok |
46 |
Correct |
8 ms |
4588 KB |
Ok |
47 |
Correct |
8 ms |
4588 KB |
Ok |
48 |
Correct |
8 ms |
4588 KB |
Ok |
49 |
Correct |
8 ms |
4588 KB |
Ok |
50 |
Correct |
8 ms |
4588 KB |
Ok |
51 |
Correct |
8 ms |
4588 KB |
Ok |
52 |
Correct |
8 ms |
4588 KB |
Ok |
53 |
Correct |
8 ms |
4588 KB |
Ok |
54 |
Correct |
69 ms |
8040 KB |
Ok |
55 |
Correct |
79 ms |
8552 KB |
Ok |
56 |
Correct |
79 ms |
8424 KB |
Ok |
57 |
Correct |
61 ms |
7484 KB |
Ok |
58 |
Correct |
73 ms |
8296 KB |
Ok |
59 |
Correct |
70 ms |
8040 KB |
Ok |
60 |
Correct |
62 ms |
7656 KB |
Ok |
61 |
Correct |
63 ms |
7912 KB |
Ok |
62 |
Correct |
80 ms |
8808 KB |
Ok |
63 |
Correct |
66 ms |
7912 KB |
Ok |
64 |
Correct |
80 ms |
8424 KB |
Ok |
65 |
Correct |
74 ms |
8296 KB |
Ok |
66 |
Correct |
68 ms |
7912 KB |
Ok |
67 |
Correct |
62 ms |
7656 KB |
Ok |
68 |
Correct |
69 ms |
8168 KB |
Ok |
69 |
Correct |
118 ms |
15208 KB |
Ok |
70 |
Correct |
118 ms |
15208 KB |
Ok |
71 |
Correct |
117 ms |
13672 KB |
Ok |
72 |
Correct |
117 ms |
15208 KB |
Ok |
73 |
Correct |
117 ms |
13928 KB |
Ok |
74 |
Correct |
115 ms |
14492 KB |
Ok |
75 |
Correct |
118 ms |
14952 KB |
Ok |
76 |
Correct |
120 ms |
15208 KB |
Ok |
77 |
Correct |
115 ms |
14184 KB |
Ok |
78 |
Correct |
121 ms |
15080 KB |
Ok |
79 |
Correct |
120 ms |
14696 KB |
Ok |
80 |
Correct |
118 ms |
13800 KB |
Ok |
81 |
Correct |
120 ms |
15208 KB |
Ok |
82 |
Correct |
117 ms |
14568 KB |
Ok |
83 |
Correct |
120 ms |
15208 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4204 KB |
Ok |
2 |
Correct |
4 ms |
4204 KB |
Ok |
3 |
Correct |
4 ms |
4204 KB |
Ok |
4 |
Correct |
4 ms |
4204 KB |
Ok |
5 |
Correct |
4 ms |
4204 KB |
Ok |
6 |
Correct |
4 ms |
4204 KB |
Ok |
7 |
Correct |
4 ms |
4204 KB |
Ok |
8 |
Correct |
4 ms |
4204 KB |
Ok |
9 |
Correct |
4 ms |
4204 KB |
Ok |
10 |
Correct |
4 ms |
4204 KB |
Ok |
11 |
Correct |
4 ms |
4204 KB |
Ok |
12 |
Correct |
4 ms |
4204 KB |
Ok |
13 |
Correct |
4 ms |
4204 KB |
Ok |
14 |
Correct |
4 ms |
4204 KB |
Ok |
15 |
Correct |
4 ms |
4204 KB |
Ok |
16 |
Correct |
4 ms |
4204 KB |
Ok |
17 |
Correct |
4 ms |
4204 KB |
Ok |
18 |
Correct |
6 ms |
4332 KB |
Ok |
19 |
Correct |
13 ms |
5100 KB |
Ok |
20 |
Correct |
9 ms |
4588 KB |
Ok |
21 |
Correct |
16 ms |
5228 KB |
Ok |
22 |
Correct |
10 ms |
4716 KB |
Ok |
23 |
Correct |
3 ms |
4204 KB |
Ok |
24 |
Correct |
4 ms |
4204 KB |
Ok |
25 |
Correct |
6 ms |
4204 KB |
Ok |
26 |
Correct |
4 ms |
4204 KB |
Ok |
27 |
Correct |
4 ms |
4204 KB |
Ok |
28 |
Correct |
4 ms |
4332 KB |
Ok |
29 |
Correct |
4 ms |
4204 KB |
Ok |
30 |
Correct |
4 ms |
4204 KB |
Ok |
31 |
Correct |
4 ms |
4204 KB |
Ok |
32 |
Correct |
4 ms |
4204 KB |
Ok |
33 |
Correct |
4 ms |
4204 KB |
Ok |
34 |
Correct |
4 ms |
4204 KB |
Ok |
35 |
Correct |
4 ms |
4204 KB |
Ok |
36 |
Correct |
4 ms |
4204 KB |
Ok |
37 |
Correct |
4 ms |
4204 KB |
Ok |
38 |
Correct |
4 ms |
4204 KB |
Ok |
39 |
Correct |
93 ms |
15332 KB |
Ok |
40 |
Correct |
78 ms |
14200 KB |
Ok |
41 |
Correct |
141 ms |
17252 KB |
Ok |
42 |
Correct |
128 ms |
15460 KB |
Ok |
43 |
Correct |
73 ms |
11880 KB |
Ok |
44 |
Correct |
114 ms |
18532 KB |
Ok |
45 |
Correct |
6 ms |
4332 KB |
Ok |
46 |
Correct |
6 ms |
4460 KB |
Ok |
47 |
Correct |
6 ms |
4460 KB |
Ok |
48 |
Correct |
6 ms |
4332 KB |
Ok |
49 |
Correct |
6 ms |
4332 KB |
Ok |
50 |
Correct |
6 ms |
4332 KB |
Ok |
51 |
Correct |
6 ms |
4332 KB |
Ok |
52 |
Correct |
7 ms |
4460 KB |
Ok |
53 |
Correct |
6 ms |
4332 KB |
Ok |
54 |
Correct |
6 ms |
4332 KB |
Ok |
55 |
Correct |
9 ms |
4588 KB |
Ok |
56 |
Correct |
8 ms |
4588 KB |
Ok |
57 |
Correct |
8 ms |
4588 KB |
Ok |
58 |
Correct |
8 ms |
4588 KB |
Ok |
59 |
Correct |
8 ms |
4588 KB |
Ok |
60 |
Correct |
8 ms |
4588 KB |
Ok |
61 |
Correct |
8 ms |
4588 KB |
Ok |
62 |
Correct |
8 ms |
4588 KB |
Ok |
63 |
Correct |
8 ms |
4588 KB |
Ok |
64 |
Correct |
8 ms |
4588 KB |
Ok |
65 |
Correct |
69 ms |
8040 KB |
Ok |
66 |
Correct |
79 ms |
8552 KB |
Ok |
67 |
Correct |
79 ms |
8424 KB |
Ok |
68 |
Correct |
61 ms |
7484 KB |
Ok |
69 |
Correct |
73 ms |
8296 KB |
Ok |
70 |
Correct |
70 ms |
8040 KB |
Ok |
71 |
Correct |
62 ms |
7656 KB |
Ok |
72 |
Correct |
63 ms |
7912 KB |
Ok |
73 |
Correct |
80 ms |
8808 KB |
Ok |
74 |
Correct |
66 ms |
7912 KB |
Ok |
75 |
Correct |
80 ms |
8424 KB |
Ok |
76 |
Correct |
74 ms |
8296 KB |
Ok |
77 |
Correct |
68 ms |
7912 KB |
Ok |
78 |
Correct |
62 ms |
7656 KB |
Ok |
79 |
Correct |
69 ms |
8168 KB |
Ok |
80 |
Correct |
118 ms |
15208 KB |
Ok |
81 |
Correct |
118 ms |
15208 KB |
Ok |
82 |
Correct |
117 ms |
13672 KB |
Ok |
83 |
Correct |
117 ms |
15208 KB |
Ok |
84 |
Correct |
117 ms |
13928 KB |
Ok |
85 |
Correct |
115 ms |
14492 KB |
Ok |
86 |
Correct |
118 ms |
14952 KB |
Ok |
87 |
Correct |
120 ms |
15208 KB |
Ok |
88 |
Correct |
115 ms |
14184 KB |
Ok |
89 |
Correct |
121 ms |
15080 KB |
Ok |
90 |
Correct |
120 ms |
14696 KB |
Ok |
91 |
Correct |
118 ms |
13800 KB |
Ok |
92 |
Correct |
120 ms |
15208 KB |
Ok |
93 |
Correct |
117 ms |
14568 KB |
Ok |
94 |
Correct |
120 ms |
15208 KB |
Ok |
95 |
Correct |
165 ms |
13924 KB |
Ok |
96 |
Correct |
237 ms |
18500 KB |
Ok |
97 |
Correct |
230 ms |
16732 KB |
Ok |
98 |
Correct |
180 ms |
15452 KB |
Ok |
99 |
Correct |
206 ms |
15580 KB |
Ok |
100 |
Correct |
215 ms |
16348 KB |
Ok |
101 |
Correct |
215 ms |
16604 KB |
Ok |
102 |
Correct |
208 ms |
16476 KB |
Ok |
103 |
Correct |
207 ms |
17044 KB |
Ok |
104 |
Correct |
240 ms |
18000 KB |
Ok |
105 |
Correct |
229 ms |
18140 KB |
Ok |
106 |
Correct |
194 ms |
16732 KB |
Ok |
107 |
Correct |
223 ms |
17244 KB |
Ok |
108 |
Correct |
244 ms |
18524 KB |
Ok |
109 |
Correct |
217 ms |
17884 KB |
Ok |
110 |
Correct |
467 ms |
49244 KB |
Ok |
111 |
Correct |
481 ms |
50140 KB |
Ok |
112 |
Correct |
463 ms |
45916 KB |
Ok |
113 |
Correct |
460 ms |
49244 KB |
Ok |
114 |
Correct |
476 ms |
45164 KB |
Ok |
115 |
Correct |
474 ms |
50260 KB |
Ok |
116 |
Correct |
477 ms |
49756 KB |
Ok |
117 |
Correct |
461 ms |
49884 KB |
Ok |
118 |
Correct |
469 ms |
44124 KB |
Ok |
119 |
Correct |
480 ms |
49116 KB |
Ok |
120 |
Correct |
470 ms |
50012 KB |
Ok |
121 |
Correct |
455 ms |
47580 KB |
Ok |
122 |
Correct |
478 ms |
49976 KB |
Ok |
123 |
Correct |
472 ms |
48092 KB |
Ok |
124 |
Correct |
469 ms |
45404 KB |
Ok |
125 |
Correct |
390 ms |
33252 KB |
Ok |