#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n, m, k=1;
cin >> n >> m;
if (n>m)
{
swap(n, m);
k=-1;
}
if (m%n==0)
{
cout << m-1 << '\n';
for (int i=0; i<m-1; i++)
cout << -k << ' ';
cout << '\n';
continue;
}
for (int 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++;
}
cout << n+m-g-1 << '\n';
long long p, q;
if (g==2)
{
q=min(1000000000LL, (1000000000*x+n-n/g)/y);
if ((q*y-n+n/g)%x)
p=(q*y-n+n/g)/x;
else
p=(q*y-n+n/g)/x-1;
}
else
{
q=min(1000000000LL, 1000000000*x/y);
if ((q*y)%x)
p=q*y/x;
else
p=q*y/x-1;
}
for (int 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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
344 KB |
Ok |
11 |
Correct |
1 ms |
348 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 |
5 ms |
860 KB |
Ok |
8 |
Correct |
2 ms |
604 KB |
Ok |
9 |
Correct |
6 ms |
1112 KB |
Ok |
10 |
Correct |
3 ms |
604 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
344 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 |
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 |
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 |
Incorrect |
47 ms |
5968 KB |
there is incorrect sequence |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
344 KB |
Ok |
11 |
Correct |
1 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
344 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 |
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 |
348 KB |
Ok |
29 |
Correct |
1 ms |
348 KB |
Ok |
30 |
Correct |
1 ms |
348 KB |
Ok |
31 |
Correct |
1 ms |
372 KB |
Ok |
32 |
Correct |
1 ms |
348 KB |
Ok |
33 |
Correct |
1 ms |
348 KB |
Ok |
34 |
Correct |
2 ms |
604 KB |
Ok |
35 |
Correct |
2 ms |
604 KB |
Ok |
36 |
Correct |
2 ms |
604 KB |
Ok |
37 |
Correct |
2 ms |
604 KB |
Ok |
38 |
Correct |
2 ms |
604 KB |
Ok |
39 |
Correct |
2 ms |
604 KB |
Ok |
40 |
Correct |
3 ms |
600 KB |
Ok |
41 |
Correct |
2 ms |
604 KB |
Ok |
42 |
Correct |
3 ms |
604 KB |
Ok |
43 |
Correct |
2 ms |
604 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
344 KB |
Ok |
11 |
Correct |
1 ms |
348 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 |
5 ms |
860 KB |
Ok |
20 |
Correct |
2 ms |
604 KB |
Ok |
21 |
Correct |
6 ms |
1112 KB |
Ok |
22 |
Correct |
3 ms |
604 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
344 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Correct |
0 ms |
348 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 |
348 KB |
Ok |
39 |
Correct |
1 ms |
348 KB |
Ok |
40 |
Correct |
1 ms |
348 KB |
Ok |
41 |
Correct |
1 ms |
372 KB |
Ok |
42 |
Correct |
1 ms |
348 KB |
Ok |
43 |
Correct |
1 ms |
348 KB |
Ok |
44 |
Correct |
2 ms |
604 KB |
Ok |
45 |
Correct |
2 ms |
604 KB |
Ok |
46 |
Correct |
2 ms |
604 KB |
Ok |
47 |
Correct |
2 ms |
604 KB |
Ok |
48 |
Correct |
2 ms |
604 KB |
Ok |
49 |
Correct |
2 ms |
604 KB |
Ok |
50 |
Correct |
3 ms |
600 KB |
Ok |
51 |
Correct |
2 ms |
604 KB |
Ok |
52 |
Correct |
3 ms |
604 KB |
Ok |
53 |
Correct |
2 ms |
604 KB |
Ok |
54 |
Correct |
34 ms |
2140 KB |
Ok |
55 |
Correct |
40 ms |
2640 KB |
Ok |
56 |
Correct |
41 ms |
2948 KB |
Ok |
57 |
Correct |
30 ms |
1876 KB |
Ok |
58 |
Correct |
36 ms |
2128 KB |
Ok |
59 |
Correct |
34 ms |
1964 KB |
Ok |
60 |
Correct |
31 ms |
1848 KB |
Ok |
61 |
Correct |
31 ms |
1880 KB |
Ok |
62 |
Correct |
40 ms |
2308 KB |
Ok |
63 |
Correct |
32 ms |
2140 KB |
Ok |
64 |
Correct |
38 ms |
2140 KB |
Ok |
65 |
Correct |
38 ms |
2540 KB |
Ok |
66 |
Correct |
33 ms |
2236 KB |
Ok |
67 |
Correct |
33 ms |
2128 KB |
Ok |
68 |
Correct |
34 ms |
2128 KB |
Ok |
69 |
Incorrect |
63 ms |
9192 KB |
there is incorrect sequence |
70 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
344 KB |
Ok |
11 |
Correct |
1 ms |
348 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 |
5 ms |
860 KB |
Ok |
20 |
Correct |
2 ms |
604 KB |
Ok |
21 |
Correct |
6 ms |
1112 KB |
Ok |
22 |
Correct |
3 ms |
604 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
344 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Correct |
0 ms |
348 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 |
348 KB |
Ok |
36 |
Correct |
0 ms |
348 KB |
Ok |
37 |
Correct |
0 ms |
348 KB |
Ok |
38 |
Correct |
0 ms |
348 KB |
Ok |
39 |
Incorrect |
47 ms |
5968 KB |
there is incorrect sequence |
40 |
Halted |
0 ms |
0 KB |
- |