Cod sursa(job #179798)

Utilizator razvi9Jurca Razvan razvi9 Data 16 aprilie 2008 12:59:10
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<cstdio>
#define m(a,b) (a)<(b)?(a):(b)
#define M(a,b) (a)>(b)?(a):(b)
const int max=1000000;
int n,a[max],b[max],c[max],left,i,j,k,p[max],viz[max],fin[max];
long long x,y;
int main()
{
	freopen("curcubeu.in","r",stdin);
	freopen("curcubeu.out","w",stdout);
	scanf("%d %lld %lld %d",&n,&x,&y,&c[0]);
	a[0]=m(x,y);
	b[0]=M(x,y);
	for(i=1;i<n;++i)
	{
		x=((long long)a[i-1]*i)%n;
		y=((long long)b[i-1]*i)%n;
		a[i]=m(x,y);
		b[i]=M(x,y);
		c[i]=((long long)c[i-1]*i)%n;
		p[i]=i;
	}
	left=n-1;
	for(i=n-1;i>0 && left;--i)
	{
		for(j=1;j<=left && p[j]<=b[i];j++)
			if(p[j]<=a[i])
			{
				viz[p[j]]=1;
				fin[p[j]]=c[i];
			}
		j=0;
		for(k=1;k<n;k++)
			if(!viz[k])
				p[++j]=k;
		left=j;
	}
	for(i=1;i<n;i++)
		printf("%d\n",fin[i]);
	fclose(stdout);
	return 0;
}