This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int MAXN = 400001;
bool w[MAXN];
int ans;
int a[MAXN];
int t;
int n, m;
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
void dfs(int v) {
if (v < 0 || v > ans || w[v]) {
return;
}
w[v] = true;
dfs(v - n);
dfs(v + m);
a[v] = t++;
}
void solve() {
cin >> n >> m;
ans = n + m - gcd(n, m) - 1;
t = 0;
fill(w, w + ans + 1, false);
for (int i = 0; i <= ans; ++i) {
dfs(i);
}
cout << ans << "\n";
for (int i = 0; i < ans; ++i) {
cout << a[i] - a[i + 1] << " ";
}
cout << "\n";
}
int main() {
#ifdef PAUNSVOKNO
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |