Pagini recente » Cod sursa (job #877162) | Cod sursa (job #1818760) | Cod sursa (job #2314763) | Cod sursa (job #2951397) | Cod sursa (job #2958641)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
#define NMAX 1000005
int n, a, b, c;;
int dr[NMAX], st[NMAX], C[NMAX], Next[NMAX], sol[NMAX];
int find_next(int pos)
{
int aux = pos;
while(Next[pos] != pos)
pos = Next[pos];
int res = pos;
pos = aux;
while(Next[pos] != res){
aux = Next[pos];
Next[pos] = res;
pos = aux;
}
return res;
}
void solve()
{
for (int i=1;i<=n;i++)
Next[i] = i;
for (int i=n-1;i>0;i--){
for (int j=find_next(st[i]);j<=dr[i];j=Next[j]){
sol[j] = C[i];
Next[j] = find_next(j+1);
}
}
}
int main()
{
fin >> n >> a >> b >> c;
if (a > b)
swap(a, b);
dr[1] = a;
st[1] = b;
C[1] = c;
for (int i=2;i<n;i++){
dr[i] = (1LL * dr[i-1] * i) % n;
st[i] = (1LL * st[i-1] * i) % n;
C[i] = (1LL * C[i-1] * i) % n;
if (st[i] > dr[i])
swap(st[i], dr[i]);
}
solve();
for (int i=1;i<n;i++){
fout << sol[i] << '\n';
}
return 0;
}