Cod sursa(job #363517)

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

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 k,j,i;
	if(a[1]>b[1])
		a[1]^=b[1]^=a[1]^=b[1];
	for(i=2;i<n;i++)
	{
		a[i]=((long long)a[i-1]*i)%n;
		b[i]=((long long)b[i-1]*i)%n;
		if(a[i]>b[i])
			a[i]^=b[i]^=a[i]^=b[i];
		c[i]=((long long)c[i-1]*i)%n;
	}
	for(i=1;i<n;i++)
		t[i]=i+1;
	for(i=n-1;i>=1;i--)
	{
        j=a[i];
        while(j<=b[i])
        {
            if(!v[j])
				v[j]=c[i];
            k=j;
            j=t[j];
            t[k]=b[i]+1;
        }
	}
	for(i=1;i<n;i++)
		printf("%d\n",v[i]);
	return 0;
}