Pagini recente » Cod sursa (job #2982514) | Cod sursa (job #2437769) | Cod sursa (job #2437959) | Cod sursa (job #3186491) | Cod sursa (job #3190119)
#include <fstream>
#define DIM 1000005
using namespace std;
ifstream cin("jstc.in");
ofstream cout("jstc.out");
int n,i,j,a[DIM],b[DIM],c[DIM],root[DIM],dim[DIM],val[DIM];
int getroot(int x){
while(root[x]!=0)
x=root[x];
return x;
}
void join(int x,int y){
x=getroot(x),y=getroot(y);
if(dim[x]<dim[y])
swap(x,y);
if(x==y)
return ;
root[y]=x;
dim[x]+=dim[y];
}
int main()
{
cin>>n>>a[1]>>b[1]>>c[1];
val[1]=-1,dim[1]=1;
for(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;
val[i]=-1;
dim[i]=1;
}
for(i=n-1;i>0;i--){
int first=min(a[i],b[i]),last=max(a[i],b[i]);
for(j=first;j<=last;j++){
if(val[j]==-1){
if(j>1&&val[j-1]!=-1)
join(j,j-1);
if(val[j+1]!=-1)
join(j,j+1);
val[j]=c[j];
}else
j+=dim[getroot(j)];
}
}
for(i=1;i<n;i++){
if(val[i]<0)
val[i]=0;
cout<<val[i]<<'\n';
}
return 0;
}