#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;
}
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 |
1 ms |
344 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 3, pans = -999999999 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Incorrect |
0 ms |
348 KB |
All the numbers must be nonzero |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 3, pans = -999999999 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 3, pans = -999999999 |
14 |
Halted |
0 ms |
0 KB |
- |