Cod sursa(job #363509)

Utilizator GheorgheMihaiMihai Gheorghe GheorgheMihai Data 13 noiembrie 2009 17:25:19
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<stdio.h>
#define nmax 1000002
int n,i;
int a[nmax],b[nmax],c[nmax],v[nmax],t[nmax];

int find(int x)
{
	if(t[x]>b[i])
	{
		v[x]=c[i];
		return t[x];
	}
	t[i]=find(t[x]);
	if(!v[i])
		v[i]=v[t[i]];
	return t[i];
}

int main()
{
	freopen("curcubeu.in","r",stdin);
	freopen("curcubeu.out","w",stdout);
	scanf("%d%d%d%d",&n,&a[1],&b[1],&c[1]);
	int j;
	if(a[1]>b[1])
		a[1]^=b[1]^=a[1]^=b[1];
	for(i=2;i<n;i++)
	{
		a[i]=(a[i-1]*i)%n;
		b[i]=(b[i-1]*i)%n;
		if(a[i]>b[i])
			a[i]^=b[i]^=a[i]^=b[i];
		c[i]=(c[i-1]*i)%n;
	}
	for(i=1;i<n;i++)
		t[i]=i+1;
	for(i=n-1;i>=1;i--)
		j=find(a[i]);
	for(i=1;i<n;i++)
		printf("%d\n",v[i]);
	return 0;
}