Pagini recente » Cod sursa (job #2138158) | Cod sursa (job #937969) | Cod sursa (job #1775289) | Cod sursa (job #222860) | Cod sursa (job #1587804)
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int Mn = 1e6 + 7;
int n;
int a[Mn],b[Mn],c[Mn],pos[Mn],sol[Mn];
int main()
{
freopen("curcubeu.in","r",stdin);
freopen("curcubeu.out","w",stdout);
scanf("%d %d %d %d",&n,&a[1],&b[1],&c[1]);
pos[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,pos[i] = i;
for (int i = n - 1;i;i--)
{
if (a[i] > b[i])
swap(a[i],b[i]);
for (int j = a[i];j <= b[i];)
if (!sol[j])
{
sol[j] = c[i];
pos[sol[j]] = j + 1;
j++;
}
else
j = pos[sol[j]];
}
for (int i = 1;i < n;printf("%d\n",sol[i]),i++);
return 0;
}