Cod sursa(job #1523302)

Utilizator tudormaximTudor Maxim tudormaxim Data 12 noiembrie 2015 16:30:07
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1000005;
long long n, a[nmax], b[nmax], c[nmax], col[nmax], next[nmax];
int main()
{
    freopen("curcubeu.in", "r", stdin);
    freopen("curcubeu.out", "w", stdout);
    int i, j;
    scanf("%lld %lld %lld %lld", &n, &a[1], &b[1], &c[1]);

    if(a[1] > b[1]) swap(a[1], b[1]);

    for(i=2; i<n; i++)
    {
        a[i]=(a[i-1]*i)%n;
        b[i]=(b[i-1]*i)%n;
        c[i]=(c[i-1]*i)%n;
        if(a[i] > b[i]) swap(a[i], b[i]);
    }

    for(i=n-1; i; i--)
        for(j=a[i]; j<=b[i]; )
        {
            if(col[j]) j=next[col[j]]+1;
            else
            {
                col[j]=c[i];
                next[col[i]]=i;
                j++;
            }
        }
    for(i=1; i<n; i++)
        printf("%d\n", col[i]);

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