Cod sursa(job #3353167)

Utilizator Alexutu008Ionita Alexandru-Dumitru Alexutu008 Data 5 mai 2026 12:11:35
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N=1e6+1;
int v[N], n;
int st_c[N], st_a[N], st_b[N], k=1;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    freopen("curcubeu.in", "r", stdin);
    freopen("curcubeu.out", "w", stdout);

    cin>>n>>st_a[k]>>st_b[k]>>st_c[k];

    for(int i=2;i<n;++i){
        ++k;
        st_a[k] = (st_a[k-1]*i)%n;
        st_b[k] = (st_b[k-1]*i)%n;
        st_c[k] = (st_c[k-1]*i)%n;
    }

    for(;k>=1;--k){
        int x=min(st_a[k], st_b[k]);
        int y=max(st_a[k], st_b[k]);
        while(!v[x] && x<=y) v[x++]=st_c[k];
    }

    for(int i=1;i<n;++i){
        cout<<v[i]<<'\n';
    }
}