Pagini recente » Cod sursa (job #1267794) | Cod sursa (job #2985857) | Cod sursa (job #2456513) | Cod sursa (job #1498378) | Cod sursa (job #2061018)
#include <bits/stdc++.h>
using namespace std;
int m;
long long n;
struct sir{
int t0, t1, a, b, x, y, z;
};
sir t, t2, e, aux;
inline void next(sir &y){
int x = ((1LL * y.t0 * y.t0) % m * y.a + (1LL * y.t1 * y.t1) % m * y.b + 1LL * y.t0 * y.x + 1LL * y.t1 * y.y + y.z) % m;
y.t0 = y.t1; y.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, &t.a, &t.b, &t.x, &t.y, &t.z, &m, &n);
e = t; aux = t;
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);
while(!(t.t1 == e.t1 && t.t0 == e.t0)){next(t); next(e); next(e); ++C;}
t = aux; t2 = aux; cr = C;
while(cr > 0) next(t2), --cr;
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;
}