Pagini recente » Cod sursa (job #1353077) | Cod sursa (job #2309382) | Cod sursa (job #1795542) | Cod sursa (job #289405) | Cod sursa (job #2784908)
#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 findd(int nr) {
if (nr != t[nr]) return t[nr] = findd(t[nr]);
return nr;
}
void unite (int st, int dr) {
t[st] = t[findd(dr)];
}
int main()
{
fin >> n >> a[1] >> b[1] >> c[1];
t[1] = 1;
for (int i = 2; i < n; ++i) {
a[i] = (1LL * a[i - 1] * i) % n;
b[i] = (1LL * b[i - 1] * i) % n;
c[i] = (1LL * c[i - 1] * i) % n;
t[i] = i;
}
t[n] = n;
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 = findd(st);
continue;
}
ans[st] = x;
unite (st, dr + 1);
if (st + 1 > dr) break;
st = findd(++st);
}
}
for (int i = 1; i < n; ++i) fout << ans[i] << '\n';
return 0;
}