Cod sursa(job #2570216)

Utilizator toadehuPuscasu Razvan Stefan toadehu Data 4 martie 2020 15:36:35
Problema Rsir Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <bits/stdc++.h>

using namespace std;

const int Nmax=7009;

int t0,t1,a,b,x,y,z,mod,p[Nmax],s[Nmax];

long long int n;

pair <int,int > testoasa,iepure;

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()
{

    ifstream fin("rsir.in");
    ofstream fout("rsir.out");
    fin>>t0>>t1>>a>>b>>x>>y>>z>>mod>>n;
    t0%=mod;
    t1%=mod;
    a%=mod;
    b%=mod;
    x%=mod;
    y%=mod;
    z%=mod;
    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={t0,t1};
    testoasa=start;
    iepure=next(start);
    while (testoasa!=iepure)
    {
        testoasa=next(testoasa);
        iepure=next(next(iepure));
    }
    int len=1;
    iepure=next(iepure);
    while (iepure!=testoasa)
    {
        iepure=next(iepure);
        len++;
    }
    iepure=start;
    testoasa=start;
    for (int i=1; i<=len; ++i)
    {
        iepure=next(iepure);
    }
    int poz=0;
    while (iepure!=testoasa)
    {
        iepure=next(iepure);
        testoasa=next(testoasa);
        poz++;
    }
    int st=(n-poz)%len;
    if (st==0)
    {
        st=len;
    }
    for (int i=1; i<=st; ++i)
    {
        iepure=next(iepure);
    }
    fout<<iepure.first;
    return 0;
}