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