Pagini recente » Cod sursa (job #2099137) | Cod sursa (job #992292) | Cod sursa (job #1255752) | Cod sursa (job #1317740) | Cod sursa (job #2061058)
#include <bits/stdc++.h>
using namespace std;
int m, a, b, x, y, z;
long long n;
int a1[7006], b1[7006];
struct sir{
int t0, t1;
};
sir t, t2, e, aux;
inline void next(sir &tr){
int x = a1[tr.t0] + b1[tr.t1];
if(x >= m) x = x - m;
tr.t0 = tr.t1; tr.t1 = x;
}
int main(){
freopen("rsir.in", "r", stdin);
freopen("rsir.out", "w", stdout);
scanf("%d%d%d%d%d%d%d%d%lld", &t.t0, &t.t1, &a, &b, &x, &y, &z, &m, &n);
x %= m; y %= m; z %= m; a %= m; b %= m;
t.t0 %= m; t.t1 %= m;
for(int i = 0; i <= m ; ++i) a1[i] = (1LL * i * i * a + 1LL * x * i) % m;
for(int i = 0; i <= m ; ++i) b1[i] = (1LL * i * i * b + 1LL * y * i + z) % m;
e = t; aux = t; t2 = aux;
next(t); next(e); next(e);
while(!(t.t1 == e.t1 && t.t0 == e.t0)){next(t); next(e); next(e);}
int C = 1, L = 0, cr = 0;
next(t); next(e); next(e); next(t2);
while(!(t.t1 == e.t1 && t.t0 == e.t0)){next(t); next(e); next(e); next(t2); ++C;}
t = aux;
while(!(t.t1 == t2.t1 && t.t0 == t2.t0)){next(t); next(t2); ++L;}
t = aux;
if(n <= L) while(n > 0) next(t), --n;
else{
while(L > 0) {next(t); --n; --L;}
int w = n % C;
while(w > 0) next(t), --w;
}
printf("%d", t.t0);
return 0;
}