Cod sursa(job #3284485)

Utilizator andiRTanasescu Andrei-Rares andiR Data 11 martie 2025 17:54:13
Problema Rsir Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.85 kb
// Author: Tanasescu Andrei-Rares
/*
     █████╗  ██████╗ ████████╗
    ██╔══██╗ ██╔══██╗╚══██╔══╝
    ███████║ ██████╔╝   ██║   
    ██╔══██║ ██╔══██╗   ██║   
    ██║  ██║ ██║  ██║   ██║   
    ╚═╝  ╚═╝ ╚═╝  ╚═╝   ╚═╝   
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>
#include <cassert>

#pragma GCC optimize("O3")

#define fi first
#define se second
#define pb push_back
#define pf push_front

using namespace std;

ifstream fin ("rsir.in");
ofstream fout ("rsir.out");

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll Nmax=1e6+5, inf=1e9+5;

int a, b, x, y, z, t0, t1, MOD, n;

pii nxt(pii t){
    return {t.se, ((ll)a*t.fi*t.fi + (ll)b*t.se*t.se + (ll)x*t.fi + (ll)y*t.se + z)%MOD};
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    fin>>t0>>t1>>a>>b>>x>>y>>z>>MOD>>n;

    pii start={t0%MOD, t1%MOD};

    pii a=nxt(start);
    pii b=nxt(nxt(start));
    while (a!=b){
        a=nxt(a);
        b=nxt(nxt(b));
    }

    int lend=0;
    a=start;
    while (a!=b){
        a=nxt(a);
        b=nxt(b);
        lend++;
    }

    int lenc=1;
    pii art=a;
    b=nxt(a);
    while (a!=b){
        b=nxt(b);
        lenc++;
    }

    if (n<lend){
        a=start;
        while (n--)
            a=nxt(a);
        
        fout<<a.fi;
    }
    else{
        n-=lend;
        n%=lenc;

        a=art;
        while (n--)
            a=nxt(a);
        fout<<a.fi;
    }


    return 0;
}