Pagini recente » Clasament pregatire_oji_5 | Cod sursa (job #1328786) | Cod sursa (job #1573924) | Cod sursa (job #422657) | Cod sursa (job #2310612)
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;
ifstream in ("rsir.in");
ofstream out ("rsir.out");
#define ll long long
#define MIN(a , b) (((a) < (b)) ? (a) : (b))
#define MAX(a , b) (((a) < (b)) ? (b) : (a))
int const nmax = 7000;
bitset <10 + nmax * nmax> frec;
int main()
{
int t0 , t1 , a , b , x , y , z , modulo ;
ll n;
in >> t0 >> t1 >> a >> b >> x >> y >> z >> modulo >> n;
t0 %= modulo;
t1 %= modulo;
int initt0 = t0, initt1 = t1;
int lim = 1 , val = 0;
while(true){
//cout << t0 << " " << t1 << '\n';
if(frec[t0 * modulo + t1] == 1) {
val = t0 * modulo + t1;
break;
}
frec[t0 * modulo + t1] = 1;
t0 = a * t0 % modulo * t0 + b * t1 % modulo * t1 + x * t0 + y * t1 + z;
t0 %= modulo;
swap(t0 , t1);
lim++;
}
t0 = initt0;
t1 = initt1;
int start = 1;
while(true){
if(t0 * modulo + t1 == val)
break;
t0 = a * t0 % modulo * t0 + b * t1 % modulo * t1 + x * t0 + y * t1 + z;
t0 %= modulo;
swap(t0 , t1);
start++;
}
//cout << start << " " << lim << '\n';
if(start <= n)
n = (n - start) % (lim - start) + start;
t0 = initt0;
t1 = initt1;
for(int i = 2 ; i <= n ; i++){
t0 = a * t0 % modulo * t0 + b * t1 % modulo * t1 + x * t0 + y * t1 + z;
t0 %= modulo;
swap(t0 , t1);
}
out << t1;
return 0;
}