#include <bits/stdc++.h>
using namespace std;
#define int long long
const int NM = 4e5, LIM = 1e6;
int T, N, M, k;
int sum[NM+5];
bool vis[NM+5];
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_rand(int l, int r){
int tmp = rng()%(r-l+1);
if (tmp < 0) tmp += r-l+1;
return l + tmp;
}
void dfs(int u){
vis[u] = 1;
if (u+N <= k){
sum[u+N] = sum[u]+1;
dfs(u+N);
}
if (u+M <= k){
sum[u+M] = sum[u]+1;
dfs(u+M);
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--){
cin >> N >> M;
if (N%M == 0){
cout << N-1 << '\n';
for (int i = 1; i < N; i++) cout << 1 << ' ';
cout << '\n';
continue;
}
if (M%N == 0){
cout << M-1 << '\n';
for (int i = 1; i < M; i++) cout << -1 << ' ';
cout << '\n';
continue;
}
k = N+M-__gcd(N, M)-1;
while (true){
for (int i = 0; i <= k; i++) vis[i] = 0;
for (int i = 0; i <= k; i++)
if (!vis[i]){
sum[i] = get_rand(-LIM, LIM);
dfs(i);
}
bool ok = 1;
for (int i = 1; i <= k; i++)
if (sum[i] == sum[i-1]) ok = 0;
if (ok) break;
}
cout << k << '\n';
for (int i = 1; i <= k; i++){
cout << sum[i]-sum[i-1] << ' ';
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Ok |
2 |
Correct |
1 ms |
348 KB |
Ok |
3 |
Correct |
1 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
756 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 |
1 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
344 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 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 |
1 ms |
348 KB |
Ok |
3 |
Correct |
1 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
756 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 |
1 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
344 KB |
Ok |
13 |
Incorrect |
1 ms |
2396 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Ok |
2 |
Correct |
1 ms |
348 KB |
Ok |
3 |
Correct |
1 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
756 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 |
1 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
344 KB |
Ok |
13 |
Incorrect |
1 ms |
2396 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Ok |
2 |
Correct |
1 ms |
348 KB |
Ok |
3 |
Correct |
1 ms |
348 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
756 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 |
1 ms |
348 KB |
Ok |
12 |
Correct |
0 ms |
344 KB |
Ok |
13 |
Incorrect |
1 ms |
2396 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |