#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 5e5+12,INF=1e9+7;
int sz,vis[N],pref[N],m,n;
vector <int> v;
void dfs(int x){
vis[x]=1;
if (x-m >= 0 && !vis[x-m]){
dfs(x-m);
}
if (x+n<=sz && !vis[x+n]){
dfs(x+n);
}
v.pb(x);
}
bool is(int x){
sz = x;
v.clear();
int i;
for (i=0;i<=sz;++i)
vis[i]=0;
for (i=0;i<=sz;++i)
if (!vis[i])dfs(i);
for (i=0;i<v.size();++i){
pref[v[i]]=i;
}
for (i=0;i<=sz;++i){
if (i-m >= 0 && pref[i] <= pref[i-m])ret 0;
if (i+n <= sz && pref[i] <= pref[i+n])ret 0;
}
ret 1;
}
main(){
ios_base::sync_with_stdio;
int t;
cin>>t;
while (t--){
int i,j;
cin>>n>>m;
int l=n+m-1-__gcd(n,m);
is(l);
cout <<l<<"\n";
for (i=1;i<=l;++i){
cout <<pref[i]-pref[i-1]<<" ";
}
endi
}
}
Compilation message
sequence.cpp: In function 'bool is(long long int)':
sequence.cpp:37:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (i=0;i<v.size();++i){
| ~^~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main(){
| ^
sequence.cpp: In function 'int main()':
sequence.cpp:48:15: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
48 | ios_base::sync_with_stdio;
| ~~~~~~~~~~^~~~~~~~~~~~~~~
sequence.cpp:48:15: warning: statement has no effect [-Wunused-value]
sequence.cpp:52:15: warning: unused variable 'j' [-Wunused-variable]
52 | int i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
3 ms |
492 KB |
Ok |
7 |
Correct |
14 ms |
1260 KB |
Ok |
8 |
Correct |
7 ms |
748 KB |
Ok |
9 |
Correct |
15 ms |
1260 KB |
Ok |
10 |
Correct |
9 ms |
876 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
0 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
114 ms |
9692 KB |
Ok |
7 |
Correct |
98 ms |
13404 KB |
Ok |
8 |
Correct |
190 ms |
16348 KB |
Ok |
9 |
Correct |
146 ms |
14300 KB |
Ok |
10 |
Correct |
74 ms |
7264 KB |
Ok |
11 |
Correct |
127 ms |
11612 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
1 ms |
364 KB |
Ok |
19 |
Correct |
1 ms |
364 KB |
Ok |
20 |
Correct |
1 ms |
364 KB |
Ok |
21 |
Correct |
0 ms |
364 KB |
Ok |
22 |
Correct |
1 ms |
364 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
3 ms |
492 KB |
Ok |
25 |
Correct |
3 ms |
492 KB |
Ok |
26 |
Correct |
3 ms |
492 KB |
Ok |
27 |
Correct |
2 ms |
492 KB |
Ok |
28 |
Correct |
2 ms |
492 KB |
Ok |
29 |
Correct |
2 ms |
364 KB |
Ok |
30 |
Correct |
2 ms |
492 KB |
Ok |
31 |
Correct |
3 ms |
492 KB |
Ok |
32 |
Correct |
2 ms |
492 KB |
Ok |
33 |
Correct |
2 ms |
492 KB |
Ok |
34 |
Correct |
6 ms |
620 KB |
Ok |
35 |
Correct |
5 ms |
748 KB |
Ok |
36 |
Correct |
6 ms |
620 KB |
Ok |
37 |
Correct |
5 ms |
748 KB |
Ok |
38 |
Correct |
5 ms |
748 KB |
Ok |
39 |
Correct |
5 ms |
620 KB |
Ok |
40 |
Correct |
6 ms |
748 KB |
Ok |
41 |
Correct |
5 ms |
620 KB |
Ok |
42 |
Correct |
6 ms |
620 KB |
Ok |
43 |
Correct |
6 ms |
748 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
3 ms |
492 KB |
Ok |
19 |
Correct |
14 ms |
1260 KB |
Ok |
20 |
Correct |
7 ms |
748 KB |
Ok |
21 |
Correct |
15 ms |
1260 KB |
Ok |
22 |
Correct |
9 ms |
876 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
1 ms |
364 KB |
Ok |
25 |
Correct |
1 ms |
364 KB |
Ok |
26 |
Correct |
1 ms |
364 KB |
Ok |
27 |
Correct |
1 ms |
364 KB |
Ok |
28 |
Correct |
1 ms |
364 KB |
Ok |
29 |
Correct |
1 ms |
364 KB |
Ok |
30 |
Correct |
1 ms |
364 KB |
Ok |
31 |
Correct |
0 ms |
364 KB |
Ok |
32 |
Correct |
1 ms |
364 KB |
Ok |
33 |
Correct |
1 ms |
364 KB |
Ok |
34 |
Correct |
3 ms |
492 KB |
Ok |
35 |
Correct |
3 ms |
492 KB |
Ok |
36 |
Correct |
3 ms |
492 KB |
Ok |
37 |
Correct |
2 ms |
492 KB |
Ok |
38 |
Correct |
2 ms |
492 KB |
Ok |
39 |
Correct |
2 ms |
364 KB |
Ok |
40 |
Correct |
2 ms |
492 KB |
Ok |
41 |
Correct |
3 ms |
492 KB |
Ok |
42 |
Correct |
2 ms |
492 KB |
Ok |
43 |
Correct |
2 ms |
492 KB |
Ok |
44 |
Correct |
6 ms |
620 KB |
Ok |
45 |
Correct |
5 ms |
748 KB |
Ok |
46 |
Correct |
6 ms |
620 KB |
Ok |
47 |
Correct |
5 ms |
748 KB |
Ok |
48 |
Correct |
5 ms |
748 KB |
Ok |
49 |
Correct |
5 ms |
620 KB |
Ok |
50 |
Correct |
6 ms |
748 KB |
Ok |
51 |
Correct |
5 ms |
620 KB |
Ok |
52 |
Correct |
6 ms |
620 KB |
Ok |
53 |
Correct |
6 ms |
748 KB |
Ok |
54 |
Correct |
85 ms |
4448 KB |
Ok |
55 |
Correct |
96 ms |
4576 KB |
Ok |
56 |
Correct |
98 ms |
4832 KB |
Ok |
57 |
Correct |
68 ms |
3808 KB |
Ok |
58 |
Correct |
79 ms |
4064 KB |
Ok |
59 |
Correct |
76 ms |
3808 KB |
Ok |
60 |
Correct |
65 ms |
3552 KB |
Ok |
61 |
Correct |
68 ms |
4028 KB |
Ok |
62 |
Correct |
90 ms |
4448 KB |
Ok |
63 |
Correct |
74 ms |
3936 KB |
Ok |
64 |
Correct |
95 ms |
4576 KB |
Ok |
65 |
Correct |
83 ms |
4320 KB |
Ok |
66 |
Correct |
78 ms |
4064 KB |
Ok |
67 |
Correct |
70 ms |
3936 KB |
Ok |
68 |
Correct |
76 ms |
4320 KB |
Ok |
69 |
Correct |
153 ms |
11744 KB |
Ok |
70 |
Correct |
158 ms |
12408 KB |
Ok |
71 |
Correct |
156 ms |
11872 KB |
Ok |
72 |
Correct |
155 ms |
11744 KB |
Ok |
73 |
Correct |
156 ms |
11484 KB |
Ok |
74 |
Correct |
154 ms |
11104 KB |
Ok |
75 |
Correct |
151 ms |
11104 KB |
Ok |
76 |
Correct |
158 ms |
12000 KB |
Ok |
77 |
Correct |
152 ms |
10720 KB |
Ok |
78 |
Correct |
154 ms |
11232 KB |
Ok |
79 |
Correct |
155 ms |
11744 KB |
Ok |
80 |
Correct |
155 ms |
11872 KB |
Ok |
81 |
Correct |
157 ms |
11360 KB |
Ok |
82 |
Correct |
158 ms |
11616 KB |
Ok |
83 |
Correct |
158 ms |
11232 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
3 ms |
492 KB |
Ok |
19 |
Correct |
14 ms |
1260 KB |
Ok |
20 |
Correct |
7 ms |
748 KB |
Ok |
21 |
Correct |
15 ms |
1260 KB |
Ok |
22 |
Correct |
9 ms |
876 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
1 ms |
364 KB |
Ok |
25 |
Correct |
1 ms |
364 KB |
Ok |
26 |
Correct |
1 ms |
364 KB |
Ok |
27 |
Correct |
1 ms |
364 KB |
Ok |
28 |
Correct |
1 ms |
364 KB |
Ok |
29 |
Correct |
1 ms |
364 KB |
Ok |
30 |
Correct |
1 ms |
364 KB |
Ok |
31 |
Correct |
0 ms |
364 KB |
Ok |
32 |
Correct |
1 ms |
364 KB |
Ok |
33 |
Correct |
1 ms |
364 KB |
Ok |
34 |
Correct |
1 ms |
364 KB |
Ok |
35 |
Correct |
1 ms |
364 KB |
Ok |
36 |
Correct |
1 ms |
364 KB |
Ok |
37 |
Correct |
1 ms |
364 KB |
Ok |
38 |
Correct |
1 ms |
364 KB |
Ok |
39 |
Correct |
114 ms |
9692 KB |
Ok |
40 |
Correct |
98 ms |
13404 KB |
Ok |
41 |
Correct |
190 ms |
16348 KB |
Ok |
42 |
Correct |
146 ms |
14300 KB |
Ok |
43 |
Correct |
74 ms |
7264 KB |
Ok |
44 |
Correct |
127 ms |
11612 KB |
Ok |
45 |
Correct |
3 ms |
492 KB |
Ok |
46 |
Correct |
3 ms |
492 KB |
Ok |
47 |
Correct |
3 ms |
492 KB |
Ok |
48 |
Correct |
2 ms |
492 KB |
Ok |
49 |
Correct |
2 ms |
492 KB |
Ok |
50 |
Correct |
2 ms |
364 KB |
Ok |
51 |
Correct |
2 ms |
492 KB |
Ok |
52 |
Correct |
3 ms |
492 KB |
Ok |
53 |
Correct |
2 ms |
492 KB |
Ok |
54 |
Correct |
2 ms |
492 KB |
Ok |
55 |
Correct |
6 ms |
620 KB |
Ok |
56 |
Correct |
5 ms |
748 KB |
Ok |
57 |
Correct |
6 ms |
620 KB |
Ok |
58 |
Correct |
5 ms |
748 KB |
Ok |
59 |
Correct |
5 ms |
748 KB |
Ok |
60 |
Correct |
5 ms |
620 KB |
Ok |
61 |
Correct |
6 ms |
748 KB |
Ok |
62 |
Correct |
5 ms |
620 KB |
Ok |
63 |
Correct |
6 ms |
620 KB |
Ok |
64 |
Correct |
6 ms |
748 KB |
Ok |
65 |
Correct |
85 ms |
4448 KB |
Ok |
66 |
Correct |
96 ms |
4576 KB |
Ok |
67 |
Correct |
98 ms |
4832 KB |
Ok |
68 |
Correct |
68 ms |
3808 KB |
Ok |
69 |
Correct |
79 ms |
4064 KB |
Ok |
70 |
Correct |
76 ms |
3808 KB |
Ok |
71 |
Correct |
65 ms |
3552 KB |
Ok |
72 |
Correct |
68 ms |
4028 KB |
Ok |
73 |
Correct |
90 ms |
4448 KB |
Ok |
74 |
Correct |
74 ms |
3936 KB |
Ok |
75 |
Correct |
95 ms |
4576 KB |
Ok |
76 |
Correct |
83 ms |
4320 KB |
Ok |
77 |
Correct |
78 ms |
4064 KB |
Ok |
78 |
Correct |
70 ms |
3936 KB |
Ok |
79 |
Correct |
76 ms |
4320 KB |
Ok |
80 |
Correct |
153 ms |
11744 KB |
Ok |
81 |
Correct |
158 ms |
12408 KB |
Ok |
82 |
Correct |
156 ms |
11872 KB |
Ok |
83 |
Correct |
155 ms |
11744 KB |
Ok |
84 |
Correct |
156 ms |
11484 KB |
Ok |
85 |
Correct |
154 ms |
11104 KB |
Ok |
86 |
Correct |
151 ms |
11104 KB |
Ok |
87 |
Correct |
158 ms |
12000 KB |
Ok |
88 |
Correct |
152 ms |
10720 KB |
Ok |
89 |
Correct |
154 ms |
11232 KB |
Ok |
90 |
Correct |
155 ms |
11744 KB |
Ok |
91 |
Correct |
155 ms |
11872 KB |
Ok |
92 |
Correct |
157 ms |
11360 KB |
Ok |
93 |
Correct |
158 ms |
11616 KB |
Ok |
94 |
Correct |
158 ms |
11232 KB |
Ok |
95 |
Correct |
198 ms |
10496 KB |
Ok |
96 |
Correct |
286 ms |
14420 KB |
Ok |
97 |
Correct |
277 ms |
12372 KB |
Ok |
98 |
Correct |
211 ms |
11732 KB |
Ok |
99 |
Correct |
247 ms |
11732 KB |
Ok |
100 |
Correct |
249 ms |
11732 KB |
Ok |
101 |
Correct |
253 ms |
13396 KB |
Ok |
102 |
Correct |
253 ms |
12372 KB |
Ok |
103 |
Correct |
244 ms |
12628 KB |
Ok |
104 |
Correct |
297 ms |
14292 KB |
Ok |
105 |
Correct |
282 ms |
14292 KB |
Ok |
106 |
Correct |
245 ms |
14420 KB |
Ok |
107 |
Correct |
267 ms |
13652 KB |
Ok |
108 |
Correct |
293 ms |
14396 KB |
Ok |
109 |
Correct |
270 ms |
15060 KB |
Ok |
110 |
Correct |
639 ms |
46420 KB |
Ok |
111 |
Correct |
662 ms |
48900 KB |
Ok |
112 |
Correct |
654 ms |
46292 KB |
Ok |
113 |
Correct |
656 ms |
48980 KB |
Ok |
114 |
Correct |
666 ms |
49492 KB |
Ok |
115 |
Correct |
653 ms |
46804 KB |
Ok |
116 |
Correct |
668 ms |
49108 KB |
Ok |
117 |
Correct |
649 ms |
48212 KB |
Ok |
118 |
Correct |
650 ms |
48696 KB |
Ok |
119 |
Correct |
652 ms |
47828 KB |
Ok |
120 |
Correct |
646 ms |
47700 KB |
Ok |
121 |
Correct |
650 ms |
47316 KB |
Ok |
122 |
Correct |
660 ms |
47700 KB |
Ok |
123 |
Correct |
670 ms |
49236 KB |
Ok |
124 |
Correct |
639 ms |
44176 KB |
Ok |
125 |
Correct |
520 ms |
32468 KB |
Ok |