Cod sursa(job #2767850)

Utilizator marcumihaiMarcu Mihai marcumihai Data 8 august 2021 11:26:18
Problema Rsir Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.61 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("rsir.in");
ofstream g("rsir.out");

int p[7001],s[7001];
long long n;
pair<int,int>testoasa,iepure;
int mod;


pair<int,int>next(pair<int,int>x)
{
    pair<int,int>a;
    a.first = x.second;
    a.second = p[x.first] + s[x.second];
    if(a.second >= mod)
        a.second -= mod;
    return a;
}


int main()
{
    int t,t2,a,b,x,y,z;
    f >> t >> t2 >> a >> b >> x >> y >> z >> mod >> n;

    long long int curent;
    for(int i = 0; i < mod; ++i)
    {
        curent = 1LL * x * i;
        curent += 1LL * a * i * i;
        curent += z;
        curent %= mod;
        p[i] = curent;
        curent = 1LL * y * i;
        curent += 1LL * b * i * i;
        curent %= mod;
        s[i] = curent;
    }
    pair<int,int>start;
    start = {t,t2};
    testoasa = start;
    iepure = next(start);
    while(testoasa != iepure)
    {
        testoasa = next(testoasa);
        iepure = next(next(iepure));
    }
    int inainteciclu = 1;
    iepure = next(iepure);
    while(iepure != testoasa)
    {
        iepure = next(iepure);
        inainteciclu++;
    }
    iepure = start;
    testoasa = start;
    for(int i = 1; i <= inainteciclu; ++i)
        iepure = next(iepure);
    int lungciclu = 0;
    while(iepure != testoasa)
    {
        iepure = next(iepure);
        testoasa = next(testoasa);
        lungciclu++;
    }
    int pasi = (n - lungciclu) % inainteciclu;
    if(pasi == 0)
        pasi = inainteciclu;
    for(int i = 1; i <= pasi; ++i)
        iepure = next(iepure);


    g << iepure.first;
}