#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
//cout.tie(0);
long long t;
cin >> t;
while (t--)
{
long long n, m, k=1;
cin >> n >> m;
if (n>m)
{
swap(n, m);
k=-1;
}
if (m%n==0)
{
cout << m-1 << '\n';
for (long long i=0; i<m-1; i++)
cout << -k << ' ';
cout << '\n';
continue;
}
for (long long i=0; i<n; i++)
a[i]=0;
long long g=gcd(n, m), ind=m%n-1, x=0, y=0;
while (ind!=(m%n-g-1+n)%n)
{
a[ind]=1;
ind=(ind+m%n)%n;
x++;
}
while (ind!=m%n-1)
{
a[ind]=-1;
ind=(ind+m%n)%n;
y++;
}
long long p, q;
if (g==2)
{
for (long long i=min(1000000000LL, (1000000000*x+n-n/g)/y); i>=1; i--)
{
if (x==1 || (i*y-n+n/g)%x==1)
{
q=i;
break;
}
}
p=(q*y-n+n/g-1)/x;
}
else
{
for (long long i=min(1000000000LL, 1000000000*x/y); i>=1; i--)
{
if (x==1 || i*y%x==1)
{
q=i;
break;
}
}
p=(q*y-1)/x;
}
cout << n+m-g-1 << '\n';
for (long long i=0; i<n+m-g-1; i++)
{
if (a[i%n]==1)
cout << p*k << ' ';
else if (a[i%n]==-1)
cout << -q*k << ' ';
else if (g==2 || i%g)
cout << k << ' ';
else
cout << -(g-2)*k << ' ';
}
cout << '\n';
}
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:66:17: warning: 'q' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | p=(q*y-1)/x;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
344 KB |
Ok |
11 |
Correct |
0 ms |
600 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
348 KB |
Ok |
7 |
Correct |
6 ms |
860 KB |
Ok |
8 |
Correct |
3 ms |
604 KB |
Ok |
9 |
Correct |
6 ms |
1116 KB |
Ok |
10 |
Correct |
4 ms |
604 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
600 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
344 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
344 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
54 ms |
6356 KB |
Ok |
7 |
Correct |
50 ms |
5972 KB |
Ok |
8 |
Correct |
84 ms |
9808 KB |
Ok |
9 |
Correct |
65 ms |
9044 KB |
Ok |
10 |
Correct |
49 ms |
4212 KB |
Ok |
11 |
Correct |
73 ms |
8244 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
344 KB |
Ok |
11 |
Correct |
0 ms |
600 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
600 KB |
Ok |
17 |
Correct |
0 ms |
348 KB |
Ok |
18 |
Correct |
0 ms |
348 KB |
Ok |
19 |
Correct |
0 ms |
348 KB |
Ok |
20 |
Correct |
0 ms |
348 KB |
Ok |
21 |
Correct |
0 ms |
348 KB |
Ok |
22 |
Correct |
0 ms |
348 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
1 ms |
348 KB |
Ok |
25 |
Correct |
1 ms |
348 KB |
Ok |
26 |
Correct |
1 ms |
348 KB |
Ok |
27 |
Correct |
1 ms |
348 KB |
Ok |
28 |
Correct |
1 ms |
480 KB |
Ok |
29 |
Correct |
1 ms |
348 KB |
Ok |
30 |
Correct |
1 ms |
348 KB |
Ok |
31 |
Correct |
1 ms |
348 KB |
Ok |
32 |
Correct |
1 ms |
452 KB |
Ok |
33 |
Correct |
1 ms |
348 KB |
Ok |
34 |
Correct |
2 ms |
604 KB |
Ok |
35 |
Correct |
3 ms |
604 KB |
Ok |
36 |
Correct |
2 ms |
664 KB |
Ok |
37 |
Correct |
3 ms |
600 KB |
Ok |
38 |
Correct |
3 ms |
600 KB |
Ok |
39 |
Correct |
5 ms |
604 KB |
Ok |
40 |
Correct |
3 ms |
604 KB |
Ok |
41 |
Correct |
3 ms |
604 KB |
Ok |
42 |
Correct |
2 ms |
604 KB |
Ok |
43 |
Correct |
3 ms |
604 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
344 KB |
Ok |
11 |
Correct |
0 ms |
600 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
348 KB |
Ok |
17 |
Correct |
0 ms |
348 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
6 ms |
860 KB |
Ok |
20 |
Correct |
3 ms |
604 KB |
Ok |
21 |
Correct |
6 ms |
1116 KB |
Ok |
22 |
Correct |
4 ms |
604 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Correct |
0 ms |
600 KB |
Ok |
27 |
Correct |
0 ms |
348 KB |
Ok |
28 |
Correct |
0 ms |
348 KB |
Ok |
29 |
Correct |
0 ms |
348 KB |
Ok |
30 |
Correct |
0 ms |
348 KB |
Ok |
31 |
Correct |
0 ms |
348 KB |
Ok |
32 |
Correct |
0 ms |
348 KB |
Ok |
33 |
Correct |
0 ms |
348 KB |
Ok |
34 |
Correct |
1 ms |
348 KB |
Ok |
35 |
Correct |
1 ms |
348 KB |
Ok |
36 |
Correct |
1 ms |
348 KB |
Ok |
37 |
Correct |
1 ms |
348 KB |
Ok |
38 |
Correct |
1 ms |
480 KB |
Ok |
39 |
Correct |
1 ms |
348 KB |
Ok |
40 |
Correct |
1 ms |
348 KB |
Ok |
41 |
Correct |
1 ms |
348 KB |
Ok |
42 |
Correct |
1 ms |
452 KB |
Ok |
43 |
Correct |
1 ms |
348 KB |
Ok |
44 |
Correct |
2 ms |
604 KB |
Ok |
45 |
Correct |
3 ms |
604 KB |
Ok |
46 |
Correct |
2 ms |
664 KB |
Ok |
47 |
Correct |
3 ms |
600 KB |
Ok |
48 |
Correct |
3 ms |
600 KB |
Ok |
49 |
Correct |
5 ms |
604 KB |
Ok |
50 |
Correct |
3 ms |
604 KB |
Ok |
51 |
Correct |
3 ms |
604 KB |
Ok |
52 |
Correct |
2 ms |
604 KB |
Ok |
53 |
Correct |
3 ms |
604 KB |
Ok |
54 |
Correct |
44 ms |
2408 KB |
Ok |
55 |
Correct |
43 ms |
2640 KB |
Ok |
56 |
Correct |
44 ms |
2980 KB |
Ok |
57 |
Correct |
32 ms |
2124 KB |
Ok |
58 |
Correct |
39 ms |
2388 KB |
Ok |
59 |
Correct |
38 ms |
2128 KB |
Ok |
60 |
Correct |
33 ms |
2128 KB |
Ok |
61 |
Correct |
33 ms |
2136 KB |
Ok |
62 |
Correct |
43 ms |
2384 KB |
Ok |
63 |
Correct |
42 ms |
2132 KB |
Ok |
64 |
Correct |
41 ms |
2420 KB |
Ok |
65 |
Correct |
40 ms |
2644 KB |
Ok |
66 |
Correct |
48 ms |
2520 KB |
Ok |
67 |
Correct |
33 ms |
2148 KB |
Ok |
68 |
Correct |
37 ms |
2104 KB |
Ok |
69 |
Correct |
70 ms |
9172 KB |
Ok |
70 |
Correct |
74 ms |
11344 KB |
Ok |
71 |
Correct |
67 ms |
7708 KB |
Ok |
72 |
Correct |
103 ms |
10008 KB |
Ok |
73 |
Correct |
67 ms |
8532 KB |
Ok |
74 |
Correct |
71 ms |
6824 KB |
Ok |
75 |
Correct |
65 ms |
7428 KB |
Ok |
76 |
Correct |
72 ms |
10952 KB |
Ok |
77 |
Correct |
64 ms |
6104 KB |
Ok |
78 |
Correct |
91 ms |
10712 KB |
Ok |
79 |
Correct |
116 ms |
9300 KB |
Ok |
80 |
Correct |
69 ms |
8784 KB |
Ok |
81 |
Correct |
70 ms |
9812 KB |
Ok |
82 |
Correct |
68 ms |
8868 KB |
Ok |
83 |
Correct |
65 ms |
6992 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
344 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
344 KB |
Ok |
11 |
Correct |
0 ms |
600 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
348 KB |
Ok |
17 |
Correct |
0 ms |
348 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
6 ms |
860 KB |
Ok |
20 |
Correct |
3 ms |
604 KB |
Ok |
21 |
Correct |
6 ms |
1116 KB |
Ok |
22 |
Correct |
4 ms |
604 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Correct |
0 ms |
600 KB |
Ok |
27 |
Correct |
0 ms |
348 KB |
Ok |
28 |
Correct |
0 ms |
348 KB |
Ok |
29 |
Correct |
0 ms |
348 KB |
Ok |
30 |
Correct |
0 ms |
348 KB |
Ok |
31 |
Correct |
0 ms |
348 KB |
Ok |
32 |
Correct |
0 ms |
348 KB |
Ok |
33 |
Correct |
0 ms |
348 KB |
Ok |
34 |
Correct |
1 ms |
348 KB |
Ok |
35 |
Correct |
0 ms |
344 KB |
Ok |
36 |
Correct |
0 ms |
348 KB |
Ok |
37 |
Correct |
0 ms |
344 KB |
Ok |
38 |
Correct |
0 ms |
348 KB |
Ok |
39 |
Correct |
54 ms |
6356 KB |
Ok |
40 |
Correct |
50 ms |
5972 KB |
Ok |
41 |
Correct |
84 ms |
9808 KB |
Ok |
42 |
Correct |
65 ms |
9044 KB |
Ok |
43 |
Correct |
49 ms |
4212 KB |
Ok |
44 |
Correct |
73 ms |
8244 KB |
Ok |
45 |
Correct |
1 ms |
348 KB |
Ok |
46 |
Correct |
1 ms |
348 KB |
Ok |
47 |
Correct |
1 ms |
348 KB |
Ok |
48 |
Correct |
1 ms |
348 KB |
Ok |
49 |
Correct |
1 ms |
480 KB |
Ok |
50 |
Correct |
1 ms |
348 KB |
Ok |
51 |
Correct |
1 ms |
348 KB |
Ok |
52 |
Correct |
1 ms |
348 KB |
Ok |
53 |
Correct |
1 ms |
452 KB |
Ok |
54 |
Correct |
1 ms |
348 KB |
Ok |
55 |
Correct |
2 ms |
604 KB |
Ok |
56 |
Correct |
3 ms |
604 KB |
Ok |
57 |
Correct |
2 ms |
664 KB |
Ok |
58 |
Correct |
3 ms |
600 KB |
Ok |
59 |
Correct |
3 ms |
600 KB |
Ok |
60 |
Correct |
5 ms |
604 KB |
Ok |
61 |
Correct |
3 ms |
604 KB |
Ok |
62 |
Correct |
3 ms |
604 KB |
Ok |
63 |
Correct |
2 ms |
604 KB |
Ok |
64 |
Correct |
3 ms |
604 KB |
Ok |
65 |
Correct |
44 ms |
2408 KB |
Ok |
66 |
Correct |
43 ms |
2640 KB |
Ok |
67 |
Correct |
44 ms |
2980 KB |
Ok |
68 |
Correct |
32 ms |
2124 KB |
Ok |
69 |
Correct |
39 ms |
2388 KB |
Ok |
70 |
Correct |
38 ms |
2128 KB |
Ok |
71 |
Correct |
33 ms |
2128 KB |
Ok |
72 |
Correct |
33 ms |
2136 KB |
Ok |
73 |
Correct |
43 ms |
2384 KB |
Ok |
74 |
Correct |
42 ms |
2132 KB |
Ok |
75 |
Correct |
41 ms |
2420 KB |
Ok |
76 |
Correct |
40 ms |
2644 KB |
Ok |
77 |
Correct |
48 ms |
2520 KB |
Ok |
78 |
Correct |
33 ms |
2148 KB |
Ok |
79 |
Correct |
37 ms |
2104 KB |
Ok |
80 |
Correct |
70 ms |
9172 KB |
Ok |
81 |
Correct |
74 ms |
11344 KB |
Ok |
82 |
Correct |
67 ms |
7708 KB |
Ok |
83 |
Correct |
103 ms |
10008 KB |
Ok |
84 |
Correct |
67 ms |
8532 KB |
Ok |
85 |
Correct |
71 ms |
6824 KB |
Ok |
86 |
Correct |
65 ms |
7428 KB |
Ok |
87 |
Correct |
72 ms |
10952 KB |
Ok |
88 |
Correct |
64 ms |
6104 KB |
Ok |
89 |
Correct |
91 ms |
10712 KB |
Ok |
90 |
Correct |
116 ms |
9300 KB |
Ok |
91 |
Correct |
69 ms |
8784 KB |
Ok |
92 |
Correct |
70 ms |
9812 KB |
Ok |
93 |
Correct |
68 ms |
8868 KB |
Ok |
94 |
Correct |
65 ms |
6992 KB |
Ok |
95 |
Correct |
94 ms |
5624 KB |
Ok |
96 |
Correct |
138 ms |
8528 KB |
Ok |
97 |
Correct |
138 ms |
7572 KB |
Ok |
98 |
Correct |
103 ms |
5972 KB |
Ok |
99 |
Correct |
128 ms |
7492 KB |
Ok |
100 |
Correct |
120 ms |
6660 KB |
Ok |
101 |
Correct |
123 ms |
7248 KB |
Ok |
102 |
Correct |
120 ms |
6744 KB |
Ok |
103 |
Correct |
121 ms |
6896 KB |
Ok |
104 |
Correct |
137 ms |
7508 KB |
Ok |
105 |
Correct |
129 ms |
7508 KB |
Ok |
106 |
Correct |
117 ms |
7368 KB |
Ok |
107 |
Correct |
124 ms |
6992 KB |
Ok |
108 |
Correct |
144 ms |
7764 KB |
Ok |
109 |
Correct |
126 ms |
8276 KB |
Ok |
110 |
Correct |
256 ms |
27872 KB |
Ok |
111 |
Correct |
280 ms |
42656 KB |
Ok |
112 |
Correct |
258 ms |
29900 KB |
Ok |
113 |
Correct |
276 ms |
37096 KB |
Ok |
114 |
Correct |
293 ms |
38016 KB |
Ok |
115 |
Correct |
297 ms |
38860 KB |
Ok |
116 |
Correct |
270 ms |
37352 KB |
Ok |
117 |
Correct |
295 ms |
39012 KB |
Ok |
118 |
Correct |
276 ms |
30448 KB |
Ok |
119 |
Correct |
330 ms |
40964 KB |
Ok |
120 |
Correct |
275 ms |
32544 KB |
Ok |
121 |
Correct |
286 ms |
30884 KB |
Ok |
122 |
Correct |
308 ms |
35276 KB |
Ok |
123 |
Correct |
318 ms |
44092 KB |
Ok |
124 |
Correct |
265 ms |
25552 KB |
Ok |
125 |
Correct |
251 ms |
23900 KB |
Ok |