Cod sursa(job #715219)

Utilizator GrimpowRadu Andrei Grimpow Data 16 martie 2012 21:02:40
Problema Curcubeu Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#define Nmax 1000000+2
#define LL long long
using namespace std;

int A[Nmax],B[Nmax],C[Nmax],Urm[Nmax],Cul[Nmax],D[Nmax];
int N;

int main(){
	int i,j,jj,aux,lcul;
	ifstream f("curcubeu.in");
	ofstream g("curcubeu.out");
	f>>N>>A[1]>>B[1]>>C[1];
	Urm[1]=1;
	for(i=2;i<N;++i){
		A[i]=((LL)A[i-1]*i)%N;
		B[i]=((LL)B[i-1]*i)%N;
		if( A[i] > B[i] ) aux=A[i],A[i]=B[i],B[i]=aux;
		C[i]=((LL)C[i-1]*i)%N;
		Urm[i]=i;
	}

    for(int i=N-1;i;i--)
        {
        for(int j=A[i];j<=B[i];)
        if(!Cul[j])
        {
        Cul[j] = C[i];
        D[j] = B[i]+1;
        j ++;
        }
        else
        j = D[j];
        }

	for(i=1;i<N;++i) g<<Cul[i]<<'\n';
    f.close();
    g.close();
    return 0;
}