Cod sursa(job #176315)
#include<stdio.h>
long n, nr, x[1000302];
typedef struct
{
long a, b, c;
} culoare;
culoare v[1000302];
inline long min(long x, long y) { return x < y ? x : y;}
inline long max(long x, long y) { return x > y ? x : y;}
int main()
{
freopen("curcubeu.in","r",stdin);
freopen("curcubeu.out","w",stdout);
scanf("%ld",&n);
scanf("%ld %ld %ld",&v[1].a, &v[1].b, &v[1].c);
long i, j, xx, yy;
nr = n - 1;
for (i = 2; i < n; i++)
{
v[i].a = ((v[i - 1].a % n) * (i % n)) % n;
v[i].b = ((v[i - 1].b % n) * (i % n)) % n;
v[i].c = ((v[i - 1].c % n) * (i % n)) % n;
}
for (i = n - 1; i >= 1; i--)
{
xx = min(v[i].a, v[i].b);
yy = max(v[i].a, v[i].b);
if (yy)
for (j = xx; j <= yy; j++)
{
if (!x[j]) { x[j] = v[i].c; nr--;}
if (!nr) break;
}
if (!nr) break;
}
for (i = 1; i < n; i++) printf("%ld\n",x[i]);
return 0;
}