Pagini recente » Cod sursa (job #2562169) | Cod sursa (job #1667941) | Cod sursa (job #2803450) | Cod sursa (job #2655931) | Cod sursa (job #2443749)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("rsir.in");
ofstream out("rsir.out");
const int dim = 7005;
int t0,t1,a,b,x,y,z,mod,n,p[dim],s[dim];
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];
a.first %= mod;
a.second %= mod;
return a;
}
int main()
{
in >> t0 >> t1 >> a >> b >> x >> y >> z >> mod >> n;
t0 %= mod;
t1 %= mod;
a %= mod;
b %= mod;
x %= mod;
y %= mod;
z %= mod;
for (int i=0; i<mod; i++)
{
p[i] = (1LL*a*i*i+x*i+z)%mod;
s[i] = (1LL*b*i*i+y*i)%mod;
}
pair<int,int> start;
start = make_pair(t0%mod,t1%mod);
testoasa = next(start);
iepure = next(next(start));
while (testoasa != iepure)
{
testoasa = next(testoasa);
iepure = next(next(iepure));
}
int len = 1;
int omg = 0;
testoasa = start;
while (testoasa != iepure)
{
testoasa = next(testoasa);
iepure = next(iepure);
omg++;
}
iepure = next(iepure);
while (testoasa != iepure)
{
iepure = next(iepure);
len++;
}
if (n > omg)
{
n = (n-omg)%len + omg;
}
testoasa = start;
for (int i=1; i<=n; i++)
{
testoasa = next(testoasa);
}
out << testoasa.first;
return 0;
}