Cod sursa(job #1533811)

Utilizator DobosDobos Paul Dobos Data 22 noiembrie 2015 23:56:01
Problema Curcubeu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int MAX = 1000005+1e4;
int A[MAX],B[MAX],C[MAX],cul[MAX],from[MAX];
int main()
{
    int n;
    fin >> n >> A[1] >> B[1] >> C[1];
    for(int 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(int i = n - 1; i >= 1; i--){
            for(int j = A[i]; j <= B[i]; j++){
                if(cul[j] != 0 ) j = from[j];
                if(cul[j] == 0 && j <= B[i]){
                    cul[j] = C[i];
                    from[j] = B[i] + 1;
                }
            }
    }
    for(int i = 1; i < n ; i++)
        fout << cul[i] << "\n";
    return 0;
}