Pagini recente » Cod sursa (job #2617305) | Cod sursa (job #2166812) | Cod sursa (job #1899871) | Cod sursa (job #711441) | Cod sursa (job #2443763)
#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)%mod+x*i+z)%mod;
s[i] = (1LL*b*(i*i)%mod+y*i)%mod;
}
pair<int,int> start;
start = make_pair(t0,t1);
testoasa = next(start);
iepure = next(testoasa);
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 = 1;
for (int i=0; i<st; i++)
{
iepure = next(iepure);
}
out << iepure.first;
return 0;
}