Cod sursa(job #2708207)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 18 februarie 2021 13:22:18
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>
using namespace std;ifstream f("curcubeu.in");ofstream g("curcubeu.out");const int dim = 1e6+2;int n;int a[dim], b[dim], c[dim], w;int sol[dim];int inv[dim];int main(){f >> n >> a[1] >> b[1] >> c[1];int i, j;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;}for(i = n - 1; i > 0; --i){if(a[i] > b[i]){w = a[i];a[i] = b[i];b[i] = w;}for(j = a[i]; j <= b[i]; ++j){if(inv[j] == 0){sol[j] = c[i];inv[j] = b[i];} else j = inv[j];}}for(i = 1; i < n; ++i)g << sol[i] << '\n';return 0;}