Cod sursa(job #1135126)

Utilizator chiriacandrei25Chiriac Andrei chiriacandrei25 Data 7 martie 2014 12:49:16
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <cstdio>
#define Nmax 1000005

using namespace std;

int N,a[Nmax],b[Nmax],c[Nmax],nxt[Nmax],cul[Nmax];

int main()
{
    int i,j;
    freopen ("curcubeu.in","r",stdin);
    freopen ("curcubeu.out","w",stdout);
    scanf("%d%d%d%d", &N,&a[1],&b[1],&c[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;
    }
    for(i=N-1;i;--i)
        for(j=a[i];j<=b[i];)
            if(!cul[j])
            {
                cul[j]=c[i];
                nxt[j]=b[i]+1;
                ++j;
            }
            else
                j=nxt[j];
    for(i=1;i<N;++i)
        printf("%d\n", cul[i]);
    return 0;
}