Pagini recente » Cod sursa (job #2224950) | Cod sursa (job #332197) | Cod sursa (job #1138207) | Cod sursa (job #1634598) | Cod sursa (job #2842948)
#include <fstream>
using namespace std;
ifstream f("curcubeu.in");
ofstream g("curcubeu.out");
const int INF = 1e6 + 10;
int a[INF], b[INF], c[INF], colour[INF], urm[INF];
int root (int x)
{
if (urm[x] != x)
urm[x] = root (urm[x]);
return urm[x];
}
int main ()
{
int n, i, j, stanga, dreapta, total;
f >> n >> a[1] >> b[1] >> c[1];
for (i = 2; i <= n - 1; i += 1)
{
a[i] = (1LL * a[i - 1] * i) % n;
b[i] = (1LL * b[i - 1] * i) % n;
c[i] = (1LL * c[i - 1] * i) % n;
}
for (i = 1; i <= n; i += 1)
urm[i] = i;
total = 0;
for (i = n - 1; i >= 1 and total < n - 1; i -= 1)
{
stanga = min (a[i], b[i]);
dreapta = max (a[i], b[i]);
j = root (stanga);
while (j <= dreapta)
{
colour[j] = c[i], total += 1;
urm[j] = j + 1;
j = root (j);
}
}
for (i = 1; i <= n - 1; i += 1)
g << colour[i] << '\n';
return 0;
}