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 namespace std;
int n, m, ti = 0, sz, pre[400005];
void dfs(int cur){
if (pre[cur]) return;
if (cur - n >= 0) dfs(cur - n);
if (cur + m <= sz) dfs(cur + m);
pre[cur] = ++ti;
}
int main(){
int tc; cin >> tc;
while (tc--){
cin >> n >> m; sz = n + m - __gcd(n, m) - 1;
ti = 0; fill(pre, pre + sz + 1, 0);
for (int i = 0; i <= sz; i++) dfs(i);
cout<<sz<<endl;
for (int i = 0; i < sz; i++) cout<<pre[i] - pre[i + 1]<<" ";
cout<<endl;
}
}
# | 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... |