Submission #48959

#TimeUsernameProblemLanguageResultExecution timeMemory
48959mrtsima22Nice sequence (IZhO18_sequence)C++17
100 / 100
807 ms43504 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...