# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
797341 | kingfran1907 | Nice sequence (IZhO18_sequence) | C++14 | 361 ms | 42788 KiB |
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;
typedef long long llint;
const int maxn = 1e6+10;
int t;
int n, m;
int dis[maxn];
int out[maxn];
int sol;
int cnt;
void dfs(int x) {
if (x < 0 || x > sol) return;
if (dis[x] != -1) return;
dis[x] = maxn;
dfs(x + n); dfs(x - m);
dis[x] = cnt++;
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
sol = n + m - 1 - __gcd(n, m);
printf("%d\n", sol);
if (n == m) {
for (int i = 0; i < sol; i++) printf("1 ");
printf("\n");
continue;
}
for (int i = 0; i <= sol; i++) dis[i] = -1;
cnt = 0;
for (int i = 0; i <= sol; i++) {
if (dis[i] == -1) dfs(i);
}
//for (int i = 0; i <= sol; i++) printf("%d ", dis[i]); printf("\n");
for (int i = 0; i < sol; i++) out[i] = dis[i + 1] - dis[i];
for (int i = n; i <= sol; i++) assert(dis[i] - dis[i - n] <= -1);
for (int i = m; i <= sol; i++) assert(dis[i] - dis[i - m] >= 1);
for (int i = 0; i < sol; i++)
printf("%d ", out[i]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | 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... |