#include<stdio.h>
#include <stdlib.h>
#define int long long
int compare(const void* a, const void* b){
return (*(int*)a - *(int*)b);
}
const int mx=1e9;
int k=0;
int re(int m,int n){
k+=(m/n)*n;
if(m%n==0)return m;
return re(n,m%n);
}
void solve(){
k=0;
int n,m;scanf("%lld %lld",&n,&m);
int mul=1;
if(n>m){
n^=m,m^=n,n^=m;
mul=-1;
}
int x=re(m,n);//when to repeat?
k--;
if(m%n==0){
printf("%lld\n",m-1);
for(int i=0;i<m-1;i++)printf("%lld ",-mul);
printf("\n");
return;
}
int ans[k],val;
if(n==1)val=0;
else val=(mx-1)/(x-1);
int boc1=(n/x),aoc1=n-boc1,boc2=(m/x),aoc2=m-boc2;
//a first
int b=(aoc1+aoc2),a=-(boc2+boc1);
if((a*aoc1)+(b*boc1)>0)a*=-1,b*=-1;
int last=-mx;
for(int i=0;i<k;i++){
if(((i%x)==(x-1)))ans[i]=b;
else ans[i]=a;
}
printf("%lld\n",k);
for(int i=0;i<k;i++)printf("%lld ",mul*ans[i]);
printf("\n");
}
int32_t main(){
int t;scanf("%lld",&t);
while(t--)solve();
}
/*
+++-
3
3 1
2 3
1 1
case
*/
Compilation message
sequence.c: In function 'solve':
sequence.c:37:9: warning: unused variable 'last' [-Wunused-variable]
37 | int last=-mx;
| ^~~~
sequence.c:30:16: warning: variable 'val' set but not used [-Wunused-but-set-variable]
30 | int ans[k],val;
| ^~~
sequence.c:16:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | int n,m;scanf("%lld %lld",&n,&m);
| ^~~~~~~~~~~~~~~~~~~~~~~~
sequence.c: In function 'main':
sequence.c:47:11: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | int t;scanf("%lld",&t);
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
416 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
420 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
344 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
416 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
348 KB |
Ok |
7 |
Correct |
5 ms |
604 KB |
Ok |
8 |
Correct |
2 ms |
604 KB |
Ok |
9 |
Correct |
5 ms |
860 KB |
Ok |
10 |
Correct |
3 ms |
600 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Incorrect |
0 ms |
348 KB |
there is incorrect sequence |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
416 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
420 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
344 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
348 KB |
Ok |
13 |
Correct |
1 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Incorrect |
0 ms |
348 KB |
there is incorrect sequence |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
416 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
420 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
344 KB |
Ok |
11 |
Correct |
0 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 |
416 KB |
Ok |
16 |
Correct |
0 ms |
348 KB |
Ok |
17 |
Correct |
1 ms |
348 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
5 ms |
604 KB |
Ok |
20 |
Correct |
2 ms |
604 KB |
Ok |
21 |
Correct |
5 ms |
860 KB |
Ok |
22 |
Correct |
3 ms |
600 KB |
Ok |
23 |
Correct |
1 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Incorrect |
0 ms |
348 KB |
there is incorrect sequence |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
416 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
420 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
344 KB |
Ok |
11 |
Correct |
0 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 |
416 KB |
Ok |
16 |
Correct |
0 ms |
348 KB |
Ok |
17 |
Correct |
1 ms |
348 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
5 ms |
604 KB |
Ok |
20 |
Correct |
2 ms |
604 KB |
Ok |
21 |
Correct |
5 ms |
860 KB |
Ok |
22 |
Correct |
3 ms |
600 KB |
Ok |
23 |
Correct |
1 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Incorrect |
0 ms |
348 KB |
there is incorrect sequence |
27 |
Halted |
0 ms |
0 KB |
- |