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>
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;
int N, M, sz;
int a[MAXN];
int used[MAXN];
int timer;
int tmr = 1;
void make(int v) {
used[v] = tmr;
if (v - N >= 0&&used[v-N]!=tmr)
make(v - N);
if (v + M <= sz &&used[v+M]!=tmr)
make(v + M);
a[v] = timer++;
}
int main() {
int T ;
cin>>T;
while(T--) {
cin>>N>>M;
sz = N + M - __gcd(N, M) - 1;
timer = 0;
tmr ++;
cout << sz << endl;
for (int i = 0; i <= sz; i++) {
if (used[i] != tmr)
make(i);
}
for (int i = 0; i < sz; i++) {
cout << a[i] - a[i+1] << " ";
}
cout << endl;
}
return 0;
}
# | 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... |