Pagini recente » Cod sursa (job #432269) | Cod sursa (job #1401929) | Cod sursa (job #1713974) | Cod sursa (job #3233604) | Cod sursa (job #534641)
Cod sursa(job #534641)
#include <cstdio>
#define ll long long
#define N 1000010
int n;
int a[N],b[N],c[N];
int rez[N];
int t[N];
inline void citire() {
scanf("%d%d%d%d",&n,&a[1],&b[1],&c[1]);
for(int i=2; i<n; ++i) {
a[i] = ((ll)a[i-1]*i) % n;
b[i] = ((ll)b[i-1]*i) % n;
c[i] = ((ll)c[i-1]*i) % n;
t[i] = i;
}
t[1] = 1;
t[n] = n;
}
inline int find(int x) {
int ret = x;
while(ret!=t[ret])
ret = t[ret];
int y;
while(x!=ret) {
y = t[x];
t[x] = ret;
x = y;
}
return ret;
}
inline void unite(int x,int y) {
x = find(x);
y = find(y);
if(y>x)
t[x] = y;
else
t[y] = x;
}
inline void rezolva() {
int st,dr;
for(int i=n-1; i>0; --i) {
if(a[i]<=b[i]) {
st = a[i];
dr = b[i];
} else {
st = b[i];
dr = a[i];
}
st = find(st);
for(; st<=dr; st=find(st)) {
rez[st] = c[i];
unite(st,st+1);
}
}
}
inline void scrie() {
for(int i=1; i<n; ++i)
printf("%d\n",rez[i]);
}
int main() {
freopen("curcubeu.in","r",stdin);
freopen("curcubeu.out","w",stdout);
citire();
rezolva();
scrie();
return 0;
}