Pagini recente » Cod sursa (job #2195268) | Cod sursa (job #1238616) | Cod sursa (job #2244487) | Cod sursa (job #2338556) | Cod sursa (job #1400485)
#include <fstream>
using namespace std;
typedef pair<int, int> Pair;
ifstream fin("rsir.in");
ofstream fout("rsir.out");
Pair init;
int x, y, z, mod, n;
int64_t a, b;
void Adv1(Pair &p) {
int aux = p.second;
p.second = (x*p.first + y*p.second + z + a*p.first*p.first + b*p.second*p.second) % mod;
p.first = aux;
}
void Adv2(Pair &p) {
int aux1 = p.first, aux2 = p.second;
p.first = (x*aux1 + y*aux2 + z + a*aux1*aux1 + b*aux2*aux2) % mod;
p.second = (x*aux2 + y*p.first + z + a*aux2*aux2 + b*p.first*p.first) % mod;
}
int main() {
fin >> init.first >> init.second >> a >> b >> x >> y >> z >> mod >> n;
init.first %= mod;
init.second %= mod;
if (n < 2) {
fout << (n ? init.second : init.first) << "\n";
return 0;
}
Pair it1 = init, it2 = init;
Adv1(it1);
Adv2(it2);
int pos = 1;
while (it1 != it2) {
if (pos == n) {
fout << it1.first << "\n";
return 0;
}
++pos;
Adv1(it1);
Adv2(it2);
}
n %= pos;
while (n--)
Adv1(it1);
fout << it1.first << "\n";
return 0;
}