Cod sursa(job #567228)

Utilizator irene_mFMI Irina Iancu irene_m Data 29 martie 2011 21:06:39
Problema Curcubeu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <cstdio>
#define infile "curcubeu.in"
#define outfile "curcubeu.out"
#define MaxN 1000002

int c[MaxN],next[MaxN];
int A,B,C,N;

void read()
{
      scanf("%d%d%d%d",&N,&A,&B,&C);
}

void swap(int &A,int &B)
{
      int aux;
      if(A>B)
      {
            aux=A; A=B; B=aux;
      }
}

void sol(int nr,int A,int B,int C)
{
      int i;
      if(nr==N)
      {
            swap(A,B);
            for(i=A;i<=B;i++)
                  c[i]=C, next[i]=B;
            return;
      }
      sol(nr+1,(A*nr)%N,(B*nr)%N,(C*nr)%N);
      swap(A,B);

      i=A;
      while(i<=B)
      {
            if(next[i]==i)
            {
                  if(!c[i])
                        c[i]=C;
                  next[i]=B;
                  i++;
            }
            else
                  i=next[i];
      }
}


void solve()
{
      int i;
      for(i=1;i<N;i++) next[i]=i;

      sol(2,A,B,C);
}


void write()
{
      int i;
      for(i=1;i<N;i++)
            printf("%d\n",c[i]);
}

int main()
{
      freopen(infile,"r",stdin);
      freopen(outfile,"w",stdout);

      read();
      solve();
      write();

      fclose(stdin);
      fclose(stdout);
      return 0;
}