Pagini recente » Cod sursa (job #3261714) | Istoria paginii runda/rglshw_2 | Cod sursa (job #1403054) | Cod sursa (job #2738761) | Cod sursa (job #2846052)
#include <fstream>
using namespace std;
ifstream cin("rsir.in");
ofstream cout("rsir.out");
long long n;
int t0, t1, a, b, x, y, z, m;
int p[10000], s[10000];
pair<int, int> iep, tes;
int nextEl(int t0, int t1) {
int sol = p[t0] + s[t1];
if(sol >= m) {
sol -= m;
}
return sol;
}
int main() {
cin >> t0 >> t1 >> a >> b >> x >> y >> z >> m >> n;
t0 %= m; t1 %= m;
long long int curent;
for(int i = 0; i < m; ++i)
{
curent = 1LL * x * i;
curent += 1LL * a * i * i;
curent += z;
curent %= m;
p[i] = curent;
curent = 1LL * y * i;
curent += 1LL * b * i * i;
curent %= m;
s[i] = curent;
}
int t2 = nextEl(t0, t1), t3 = nextEl(t1, t2);
int t = 1;
iep = {t2, t3}; tes = {t1, t2};
while(iep != tes) {
t++;
int x = nextEl(tes.first, tes.second);
tes = {tes.second, x};
int y = nextEl(iep.first, iep.second);
int z = nextEl(iep.second, y);
iep = {y, z};
}
int len = t;
t = 0;
tes = {t0, t1};
while(iep != tes) {
t++;
int x = nextEl(tes.first, tes.second);
tes = {tes.second, x};
int y = nextEl(iep.first, iep.second);
iep = {iep.second, y};
}
n = (n + 1 - t) % len + t - 1;
if(n == 0) {
cout << t0;
}
else if(n == 1) {
cout << t1;
}
else {
for(int i = 1; i < n; i++) {
int t2 = nextEl(t0, t1);
t0 = t1; t1 = t2;
}
cout << t1;
}
return 0;
}