Cod sursa(job #1587804)

Utilizator DrumeaVDrumea Vasile DrumeaV Data 2 februarie 2016 16:46:12
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

const int Mn = 1e6 + 7;

int n;
int a[Mn],b[Mn],c[Mn],pos[Mn],sol[Mn];

int main()
{
    freopen("curcubeu.in","r",stdin);
    freopen("curcubeu.out","w",stdout);

     scanf("%d %d %d %d",&n,&a[1],&b[1],&c[1]);
     pos[1] = 1;

     for (int 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,pos[i] = i;

     for (int i = n - 1;i;i--)
     {
         if (a[i] > b[i])
            swap(a[i],b[i]);

         for (int j = a[i];j <= b[i];)
             if (!sol[j])
             {
                 sol[j] = c[i];
                 pos[sol[j]] = j + 1;
                 j++;
             }
           else
                 j = pos[sol[j]];
     }

     for (int i = 1;i < n;printf("%d\n",sol[i]),i++);

  return 0;
}