Pagini recente » Cod sursa (job #1286560) | Cod sursa (job #2804014) | Cod sursa (job #2246141) | Cod sursa (job #3151545) | Cod sursa (job #2784895)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int nmax = 1000006;
int n, a[nmax], b[nmax], c[nmax], ans[nmax], t[nmax];
int main()
{
fin >> n >> a[1] >> b[1] >> c[1];
t[1] = 1;
for (int i = 2; i < n; ++i) {
a[i] = (a[i - 1] * i) % n;
b[i] = (b[i - 1] * i) % n;
c[i] = (c[i - 1] * i) % n;
t[i] = i;
}
t[n] = n + 1;
for (int i = n - 1; i >= 1; --i) {
int st = a[i], dr = b[i], x = c[i];
if (st > dr) swap(st, dr);
while (st <= dr) {
if (st != t[st]) {
st = t[++st];
continue;
}
ans[st] = x;
t[st] = dr + 1;
if (st + 1 > dr) break;
st = t[++st];
}
}
for (int i = 1; i < n; ++i) fout << ans[i] << '\n';
return 0;
}