#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,mxn=400000;
int k=0;
int *adj[400000+10],sz[400000+10],vis[400000+10],ord[400000+10],cnt=0;
int what[400000+10];
void ts(int cur){
vis[cur]=1;
for(int i=0;i<sz[cur];i++)if(!vis[adj[cur][i]])ts(adj[cur][i]);
ord[cnt++]=cur;
}
void re(int m,int n){
//get length
k+=(m/n)*n;
if(m%n)re(n,m%n);
}
void solve(){
k=0,cnt=0;
int n,m;scanf("%lld %lld",&n,&m);
int mul=-1;
if(n>m){
n^=m,m^=n,n^=m;
mul=1;
}
re(m,n);
k--;
for(int i=0;i<=k;i++){
if(i-m>=0){
adj[i] = (int *)realloc(adj[i],(sz[i] + 1)*sizeof(int));
adj[i][sz[i]++]=i-m;
}
if(i-n>=0){
adj[i-n]=(int *)realloc(adj[i-n],(sz[i-n] + 1)*sizeof(int));
adj[i-n][sz[i-n]++]=i;
}
}
//get length
printf("%lld\n",k);
for(int i=0;i<=k;i++)if(!vis[i])ts(i);
for(int i=cnt;i>=0;i--)what[ord[i]]=(k-i);
for(int i=1;i<=k;i++)printf("%lld ",mul*(what[i]-what[i-1]));
for(int i=0;i<=k;i++){
if(adj[i]!=NULL)free(adj[i]);
adj[i]=NULL;
sz[i]=what[i]=vis[i]=0;
}
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:23:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | int n,m;scanf("%lld %lld",&n,&m);
| ^~~~~~~~~~~~~~~~~~~~~~~~
sequence.c: In function 'main':
sequence.c:54:11: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | int t;scanf("%lld",&t);
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Ok |
2 |
Correct |
0 ms |
2396 KB |
Ok |
3 |
Correct |
0 ms |
2396 KB |
Ok |
4 |
Correct |
1 ms |
2396 KB |
Ok |
5 |
Correct |
1 ms |
2396 KB |
Ok |
6 |
Correct |
1 ms |
2396 KB |
Ok |
7 |
Correct |
1 ms |
2396 KB |
Ok |
8 |
Correct |
0 ms |
2396 KB |
Ok |
9 |
Correct |
1 ms |
2396 KB |
Ok |
10 |
Correct |
0 ms |
2396 KB |
Ok |
11 |
Correct |
1 ms |
2396 KB |
Ok |
12 |
Correct |
1 ms |
2396 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Ok |
2 |
Correct |
1 ms |
2396 KB |
Ok |
3 |
Correct |
1 ms |
2396 KB |
Ok |
4 |
Correct |
0 ms |
2396 KB |
Ok |
5 |
Correct |
0 ms |
2396 KB |
Ok |
6 |
Correct |
2 ms |
2652 KB |
Ok |
7 |
Correct |
8 ms |
5724 KB |
Ok |
8 |
Correct |
4 ms |
2904 KB |
Ok |
9 |
Correct |
10 ms |
5724 KB |
Ok |
10 |
Correct |
9 ms |
3164 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Ok |
2 |
Correct |
0 ms |
2396 KB |
Ok |
3 |
Correct |
1 ms |
2396 KB |
Ok |
4 |
Correct |
1 ms |
2396 KB |
Ok |
5 |
Correct |
1 ms |
2392 KB |
Ok |
6 |
Correct |
0 ms |
2396 KB |
Ok |
7 |
Correct |
0 ms |
2396 KB |
Ok |
8 |
Correct |
0 ms |
2396 KB |
Ok |
9 |
Correct |
0 ms |
2396 KB |
Ok |
10 |
Correct |
1 ms |
2396 KB |
Ok |
11 |
Correct |
1 ms |
2396 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Ok |
2 |
Correct |
0 ms |
2396 KB |
Ok |
3 |
Correct |
1 ms |
2396 KB |
Ok |
4 |
Correct |
1 ms |
2392 KB |
Ok |
5 |
Correct |
0 ms |
2396 KB |
Ok |
6 |
Correct |
79 ms |
19476 KB |
Ok |
7 |
Correct |
61 ms |
19028 KB |
Ok |
8 |
Correct |
123 ms |
24316 KB |
Ok |
9 |
Correct |
101 ms |
23376 KB |
Ok |
10 |
Correct |
59 ms |
13392 KB |
Ok |
11 |
Correct |
88 ms |
23632 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Ok |
2 |
Correct |
0 ms |
2396 KB |
Ok |
3 |
Correct |
0 ms |
2396 KB |
Ok |
4 |
Correct |
1 ms |
2396 KB |
Ok |
5 |
Correct |
1 ms |
2396 KB |
Ok |
6 |
Correct |
1 ms |
2396 KB |
Ok |
7 |
Correct |
1 ms |
2396 KB |
Ok |
8 |
Correct |
0 ms |
2396 KB |
Ok |
9 |
Correct |
1 ms |
2396 KB |
Ok |
10 |
Correct |
0 ms |
2396 KB |
Ok |
11 |
Correct |
1 ms |
2396 KB |
Ok |
12 |
Correct |
1 ms |
2396 KB |
Ok |
13 |
Correct |
1 ms |
2396 KB |
Ok |
14 |
Correct |
0 ms |
2396 KB |
Ok |
15 |
Correct |
1 ms |
2396 KB |
Ok |
16 |
Correct |
1 ms |
2396 KB |
Ok |
17 |
Correct |
1 ms |
2392 KB |
Ok |
18 |
Correct |
0 ms |
2396 KB |
Ok |
19 |
Correct |
0 ms |
2396 KB |
Ok |
20 |
Correct |
0 ms |
2396 KB |
Ok |
21 |
Correct |
0 ms |
2396 KB |
Ok |
22 |
Correct |
1 ms |
2396 KB |
Ok |
23 |
Correct |
1 ms |
2396 KB |
Ok |
24 |
Correct |
2 ms |
2648 KB |
Ok |
25 |
Correct |
2 ms |
2712 KB |
Ok |
26 |
Correct |
2 ms |
2652 KB |
Ok |
27 |
Correct |
2 ms |
2652 KB |
Ok |
28 |
Correct |
2 ms |
2652 KB |
Ok |
29 |
Correct |
2 ms |
2648 KB |
Ok |
30 |
Correct |
2 ms |
2648 KB |
Ok |
31 |
Correct |
2 ms |
2648 KB |
Ok |
32 |
Correct |
2 ms |
2652 KB |
Ok |
33 |
Correct |
2 ms |
2652 KB |
Ok |
34 |
Correct |
3 ms |
2904 KB |
Ok |
35 |
Correct |
3 ms |
2904 KB |
Ok |
36 |
Correct |
3 ms |
2908 KB |
Ok |
37 |
Correct |
3 ms |
2900 KB |
Ok |
38 |
Correct |
3 ms |
3032 KB |
Ok |
39 |
Correct |
3 ms |
2908 KB |
Ok |
40 |
Correct |
3 ms |
2908 KB |
Ok |
41 |
Correct |
3 ms |
2880 KB |
Ok |
42 |
Correct |
4 ms |
2908 KB |
Ok |
43 |
Correct |
4 ms |
2908 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Ok |
2 |
Correct |
0 ms |
2396 KB |
Ok |
3 |
Correct |
0 ms |
2396 KB |
Ok |
4 |
Correct |
1 ms |
2396 KB |
Ok |
5 |
Correct |
1 ms |
2396 KB |
Ok |
6 |
Correct |
1 ms |
2396 KB |
Ok |
7 |
Correct |
1 ms |
2396 KB |
Ok |
8 |
Correct |
0 ms |
2396 KB |
Ok |
9 |
Correct |
1 ms |
2396 KB |
Ok |
10 |
Correct |
0 ms |
2396 KB |
Ok |
11 |
Correct |
1 ms |
2396 KB |
Ok |
12 |
Correct |
1 ms |
2396 KB |
Ok |
13 |
Correct |
1 ms |
2396 KB |
Ok |
14 |
Correct |
1 ms |
2396 KB |
Ok |
15 |
Correct |
1 ms |
2396 KB |
Ok |
16 |
Correct |
0 ms |
2396 KB |
Ok |
17 |
Correct |
0 ms |
2396 KB |
Ok |
18 |
Correct |
2 ms |
2652 KB |
Ok |
19 |
Correct |
8 ms |
5724 KB |
Ok |
20 |
Correct |
4 ms |
2904 KB |
Ok |
21 |
Correct |
10 ms |
5724 KB |
Ok |
22 |
Correct |
9 ms |
3164 KB |
Ok |
23 |
Correct |
1 ms |
2396 KB |
Ok |
24 |
Correct |
0 ms |
2396 KB |
Ok |
25 |
Correct |
1 ms |
2396 KB |
Ok |
26 |
Correct |
1 ms |
2396 KB |
Ok |
27 |
Correct |
1 ms |
2392 KB |
Ok |
28 |
Correct |
0 ms |
2396 KB |
Ok |
29 |
Correct |
0 ms |
2396 KB |
Ok |
30 |
Correct |
0 ms |
2396 KB |
Ok |
31 |
Correct |
0 ms |
2396 KB |
Ok |
32 |
Correct |
1 ms |
2396 KB |
Ok |
33 |
Correct |
1 ms |
2396 KB |
Ok |
34 |
Correct |
2 ms |
2648 KB |
Ok |
35 |
Correct |
2 ms |
2712 KB |
Ok |
36 |
Correct |
2 ms |
2652 KB |
Ok |
37 |
Correct |
2 ms |
2652 KB |
Ok |
38 |
Correct |
2 ms |
2652 KB |
Ok |
39 |
Correct |
2 ms |
2648 KB |
Ok |
40 |
Correct |
2 ms |
2648 KB |
Ok |
41 |
Correct |
2 ms |
2648 KB |
Ok |
42 |
Correct |
2 ms |
2652 KB |
Ok |
43 |
Correct |
2 ms |
2652 KB |
Ok |
44 |
Correct |
3 ms |
2904 KB |
Ok |
45 |
Correct |
3 ms |
2904 KB |
Ok |
46 |
Correct |
3 ms |
2908 KB |
Ok |
47 |
Correct |
3 ms |
2900 KB |
Ok |
48 |
Correct |
3 ms |
3032 KB |
Ok |
49 |
Correct |
3 ms |
2908 KB |
Ok |
50 |
Correct |
3 ms |
2908 KB |
Ok |
51 |
Correct |
3 ms |
2880 KB |
Ok |
52 |
Correct |
4 ms |
2908 KB |
Ok |
53 |
Correct |
4 ms |
2908 KB |
Ok |
54 |
Correct |
52 ms |
10584 KB |
Ok |
55 |
Correct |
74 ms |
10764 KB |
Ok |
56 |
Correct |
61 ms |
11120 KB |
Ok |
57 |
Correct |
45 ms |
11024 KB |
Ok |
58 |
Correct |
62 ms |
10320 KB |
Ok |
59 |
Correct |
61 ms |
9688 KB |
Ok |
60 |
Correct |
45 ms |
10780 KB |
Ok |
61 |
Correct |
43 ms |
10064 KB |
Ok |
62 |
Correct |
69 ms |
10484 KB |
Ok |
63 |
Correct |
51 ms |
11088 KB |
Ok |
64 |
Correct |
66 ms |
10832 KB |
Ok |
65 |
Correct |
57 ms |
10324 KB |
Ok |
66 |
Correct |
50 ms |
10320 KB |
Ok |
67 |
Correct |
42 ms |
10096 KB |
Ok |
68 |
Correct |
52 ms |
10320 KB |
Ok |
69 |
Correct |
130 ms |
19796 KB |
Ok |
70 |
Correct |
131 ms |
19536 KB |
Ok |
71 |
Correct |
132 ms |
18512 KB |
Ok |
72 |
Correct |
119 ms |
19844 KB |
Ok |
73 |
Correct |
128 ms |
19024 KB |
Ok |
74 |
Correct |
133 ms |
18920 KB |
Ok |
75 |
Correct |
127 ms |
19284 KB |
Ok |
76 |
Correct |
139 ms |
20040 KB |
Ok |
77 |
Correct |
127 ms |
18260 KB |
Ok |
78 |
Correct |
132 ms |
19940 KB |
Ok |
79 |
Correct |
127 ms |
19028 KB |
Ok |
80 |
Correct |
127 ms |
19664 KB |
Ok |
81 |
Correct |
128 ms |
19828 KB |
Ok |
82 |
Correct |
124 ms |
19280 KB |
Ok |
83 |
Correct |
125 ms |
19304 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Ok |
2 |
Correct |
0 ms |
2396 KB |
Ok |
3 |
Correct |
0 ms |
2396 KB |
Ok |
4 |
Correct |
1 ms |
2396 KB |
Ok |
5 |
Correct |
1 ms |
2396 KB |
Ok |
6 |
Correct |
1 ms |
2396 KB |
Ok |
7 |
Correct |
1 ms |
2396 KB |
Ok |
8 |
Correct |
0 ms |
2396 KB |
Ok |
9 |
Correct |
1 ms |
2396 KB |
Ok |
10 |
Correct |
0 ms |
2396 KB |
Ok |
11 |
Correct |
1 ms |
2396 KB |
Ok |
12 |
Correct |
1 ms |
2396 KB |
Ok |
13 |
Correct |
1 ms |
2396 KB |
Ok |
14 |
Correct |
1 ms |
2396 KB |
Ok |
15 |
Correct |
1 ms |
2396 KB |
Ok |
16 |
Correct |
0 ms |
2396 KB |
Ok |
17 |
Correct |
0 ms |
2396 KB |
Ok |
18 |
Correct |
2 ms |
2652 KB |
Ok |
19 |
Correct |
8 ms |
5724 KB |
Ok |
20 |
Correct |
4 ms |
2904 KB |
Ok |
21 |
Correct |
10 ms |
5724 KB |
Ok |
22 |
Correct |
9 ms |
3164 KB |
Ok |
23 |
Correct |
1 ms |
2396 KB |
Ok |
24 |
Correct |
0 ms |
2396 KB |
Ok |
25 |
Correct |
1 ms |
2396 KB |
Ok |
26 |
Correct |
1 ms |
2396 KB |
Ok |
27 |
Correct |
1 ms |
2392 KB |
Ok |
28 |
Correct |
0 ms |
2396 KB |
Ok |
29 |
Correct |
0 ms |
2396 KB |
Ok |
30 |
Correct |
0 ms |
2396 KB |
Ok |
31 |
Correct |
0 ms |
2396 KB |
Ok |
32 |
Correct |
1 ms |
2396 KB |
Ok |
33 |
Correct |
1 ms |
2396 KB |
Ok |
34 |
Correct |
1 ms |
2396 KB |
Ok |
35 |
Correct |
0 ms |
2396 KB |
Ok |
36 |
Correct |
1 ms |
2396 KB |
Ok |
37 |
Correct |
1 ms |
2392 KB |
Ok |
38 |
Correct |
0 ms |
2396 KB |
Ok |
39 |
Correct |
79 ms |
19476 KB |
Ok |
40 |
Correct |
61 ms |
19028 KB |
Ok |
41 |
Correct |
123 ms |
24316 KB |
Ok |
42 |
Correct |
101 ms |
23376 KB |
Ok |
43 |
Correct |
59 ms |
13392 KB |
Ok |
44 |
Correct |
88 ms |
23632 KB |
Ok |
45 |
Correct |
2 ms |
2648 KB |
Ok |
46 |
Correct |
2 ms |
2712 KB |
Ok |
47 |
Correct |
2 ms |
2652 KB |
Ok |
48 |
Correct |
2 ms |
2652 KB |
Ok |
49 |
Correct |
2 ms |
2652 KB |
Ok |
50 |
Correct |
2 ms |
2648 KB |
Ok |
51 |
Correct |
2 ms |
2648 KB |
Ok |
52 |
Correct |
2 ms |
2648 KB |
Ok |
53 |
Correct |
2 ms |
2652 KB |
Ok |
54 |
Correct |
2 ms |
2652 KB |
Ok |
55 |
Correct |
3 ms |
2904 KB |
Ok |
56 |
Correct |
3 ms |
2904 KB |
Ok |
57 |
Correct |
3 ms |
2908 KB |
Ok |
58 |
Correct |
3 ms |
2900 KB |
Ok |
59 |
Correct |
3 ms |
3032 KB |
Ok |
60 |
Correct |
3 ms |
2908 KB |
Ok |
61 |
Correct |
3 ms |
2908 KB |
Ok |
62 |
Correct |
3 ms |
2880 KB |
Ok |
63 |
Correct |
4 ms |
2908 KB |
Ok |
64 |
Correct |
4 ms |
2908 KB |
Ok |
65 |
Correct |
52 ms |
10584 KB |
Ok |
66 |
Correct |
74 ms |
10764 KB |
Ok |
67 |
Correct |
61 ms |
11120 KB |
Ok |
68 |
Correct |
45 ms |
11024 KB |
Ok |
69 |
Correct |
62 ms |
10320 KB |
Ok |
70 |
Correct |
61 ms |
9688 KB |
Ok |
71 |
Correct |
45 ms |
10780 KB |
Ok |
72 |
Correct |
43 ms |
10064 KB |
Ok |
73 |
Correct |
69 ms |
10484 KB |
Ok |
74 |
Correct |
51 ms |
11088 KB |
Ok |
75 |
Correct |
66 ms |
10832 KB |
Ok |
76 |
Correct |
57 ms |
10324 KB |
Ok |
77 |
Correct |
50 ms |
10320 KB |
Ok |
78 |
Correct |
42 ms |
10096 KB |
Ok |
79 |
Correct |
52 ms |
10320 KB |
Ok |
80 |
Correct |
130 ms |
19796 KB |
Ok |
81 |
Correct |
131 ms |
19536 KB |
Ok |
82 |
Correct |
132 ms |
18512 KB |
Ok |
83 |
Correct |
119 ms |
19844 KB |
Ok |
84 |
Correct |
128 ms |
19024 KB |
Ok |
85 |
Correct |
133 ms |
18920 KB |
Ok |
86 |
Correct |
127 ms |
19284 KB |
Ok |
87 |
Correct |
139 ms |
20040 KB |
Ok |
88 |
Correct |
127 ms |
18260 KB |
Ok |
89 |
Correct |
132 ms |
19940 KB |
Ok |
90 |
Correct |
127 ms |
19028 KB |
Ok |
91 |
Correct |
127 ms |
19664 KB |
Ok |
92 |
Correct |
128 ms |
19828 KB |
Ok |
93 |
Correct |
124 ms |
19280 KB |
Ok |
94 |
Correct |
125 ms |
19304 KB |
Ok |
95 |
Correct |
139 ms |
22948 KB |
Ok |
96 |
Correct |
218 ms |
32080 KB |
Ok |
97 |
Correct |
220 ms |
26812 KB |
Ok |
98 |
Correct |
136 ms |
27392 KB |
Ok |
99 |
Correct |
177 ms |
25360 KB |
Ok |
100 |
Correct |
187 ms |
25680 KB |
Ok |
101 |
Correct |
194 ms |
29540 KB |
Ok |
102 |
Correct |
169 ms |
26708 KB |
Ok |
103 |
Correct |
181 ms |
28660 KB |
Ok |
104 |
Correct |
214 ms |
30288 KB |
Ok |
105 |
Correct |
212 ms |
31820 KB |
Ok |
106 |
Correct |
170 ms |
32080 KB |
Ok |
107 |
Correct |
200 ms |
29992 KB |
Ok |
108 |
Correct |
219 ms |
31320 KB |
Ok |
109 |
Correct |
180 ms |
33364 KB |
Ok |
110 |
Correct |
748 ms |
72788 KB |
Ok |
111 |
Correct |
804 ms |
73808 KB |
Ok |
112 |
Correct |
822 ms |
66096 KB |
Ok |
113 |
Correct |
702 ms |
73296 KB |
Ok |
114 |
Correct |
803 ms |
73744 KB |
Ok |
115 |
Correct |
764 ms |
72864 KB |
Ok |
116 |
Correct |
761 ms |
72804 KB |
Ok |
117 |
Correct |
747 ms |
73300 KB |
Ok |
118 |
Correct |
818 ms |
68472 KB |
Ok |
119 |
Correct |
780 ms |
72784 KB |
Ok |
120 |
Correct |
770 ms |
72916 KB |
Ok |
121 |
Correct |
730 ms |
73812 KB |
Ok |
122 |
Correct |
704 ms |
70484 KB |
Ok |
123 |
Correct |
782 ms |
73296 KB |
Ok |
124 |
Correct |
713 ms |
66388 KB |
Ok |
125 |
Correct |
409 ms |
38488 KB |
Ok |