Pagini recente » Cod sursa (job #3005082) | Cod sursa (job #276855) | Cod sursa (job #1066497) | Cod sursa (job #975023) | Cod sursa (job #1678806)
#include<fstream>
//#define f first
//#define s second
using namespace std;
int a, b, x, y, z, nr, i, nr1, m, aux;
struct pintint{
int s;
int f;
};
pintint frst, p, q;
long long n;
int v[7005], w[7005];
ifstream fin("rsir.in");
ofstream fout("rsir.out");
inline void next(pintint p, pintint &pnext){
pnext.f = p.s;
pnext.s = v[p.f] + w[p.s] + z;
if(pnext.s >= m){
pnext.s -= m;
}
if(pnext.s >= m){
pnext.s -= m;
}
}
int main(){
fin>> frst.f >> frst.s >> a >> b >> x >> y >> z >> m >> n;
frst.f %= m;
frst.s %= m;
a %=m;
b %= m;
x %= m;
y %= m;
z %= m;
for(i = 0; i < m; i++){
v[i] = (a * i % m * i + x * i) % m;
w[i] = (b * i % m * i + y * i) % m;
}
p = q = frst;
do{
next(p, p);
next(q, q);
next(q, q);
}while(p.f != q.f || p.s != q.s);
do{
nr++;
next(p, p);
}while(p.f != q.f || p.s != q.s);
p = q = frst;
for(i = 1; i <= nr; i++){
next(p, p);
}
while(p.f != q.f || p.s != q.s){
nr1++;
next(p, p);
next(q, q);
}
if(n < nr1){
p = frst;
for(i = 1; i <= n; i++){
next(p, p);
}
fout<< p.f <<"\n";
}
else{
/* p = frst;
for(i = 1; i <= nr1; i++){
p = next(p);
}*/
n -= nr1;
aux = n % nr;
for(i = 1; i <= aux; i++){
next(p, p);
}
fout<< p.f <<"\n";
}
return 0;
}