Cod sursa(job #3240676)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 19 august 2024 18:08:26
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int Max = 1000000;
long long n, a[Max + 2], b[Max + 2], c[Max + 2];
long long r[Max + 2], i, j;

int main() {
    fin >> 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;

        if(a[i] > b[i]) swap(a[i], b[i]);
    }

    for(i = n; i >= 1; i--) {
        for(j = a[i]; j <= b[i]; j++) {
            if(!urm[j]) {
                urm[j] = b[i];
                r[j] = c[i];
            }
            else j = urm[j];
        }
    }
    for(i = 1; i < n; i++) fout << r[i] << "\n";

    return 0;
}