Pagini recente » Cod sursa (job #1669638) | Cod sursa (job #2819707) | Cod sursa (job #420648) | Cod sursa (job #2686295) | Cod sursa (job #2578215)
#include <bits/stdc++.h>
using namespace std;
ifstream f("rsir.in");
ofstream g("rsir.out");
//-------------------------------------------------------------
///Globale
int t,t2,a,b,x,y,z,mod,p[7001],s[7001];
long long n;
pair<int,int>testoasa,iepure;
//-------------------------------------------------------------
///Functii
void citire();
void rezolvare();
void afisare();
//-------------------------------------------------------------
int main()
{
citire();
rezolvare();
afisare();
return 0;
}
//-------------------------------------------------------------
void afisare()
{
g << iepure.first;
}
//-------------------------------------------------------------
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;
}
//-------------------------------------------------------------
void rezolvare()
{
t %= mod;
t2 %= 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 = {t,t2};
testoasa = start;
iepure = next(start);
while(testoasa != iepure)
{
testoasa = next(testoasa);
iepure = next(next(iepure));
}
int nr = 1;
iepure = next(iepure);
while(iepure != testoasa)
{
iepure = next(iepure);
nr++;
}
iepure = start;
testoasa = start;
for(int i = 1; i <= nr; ++i)
iepure = next(iepure);
int poz = 0;
while(iepure != testoasa)
{
iepure = next(iepure);
testoasa = next(testoasa);
poz++;
}
int st = (n - poz) % nr;
if(st == 0)
st = nr;
for(int i = 1; i <= st; ++i)
iepure = next(iepure);
}
//-------------------------------------------------------------
void citire()
{
f >> t >> t2 >> a >> b >> x >> y >> z >> mod >> n;
}