Pagini recente » Cod sursa (job #453930) | Cod sursa (job #2536210) | Cod sursa (job #318098) | Cod sursa (job #976819) | Cod sursa (job #1552190)
#include <fstream>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
ifstream f("rsir.in");
ofstream g("rsir.out");
int t0, t1, a, b, x, y, z, m, n;
f >> t0 >> t1 >> a >> b >> x >> y >> z >> m >> n;
auto next = [&](const pair<int, int>& p){
return make_pair(p.second,
((long long)a * (long long)p.first * (long long)p.first +
(long long)b * (long long)p.second * (long long)p.second +
(long long)x * (long long)p.first + (long long)y *(long long) p.second + (long long)z)%m); };
pair<int, int> tortoise(t0, t1), hare(t0, t1);
int dist = 1;
hare = next(hare);
for( ; tortoise != hare; tortoise = next(tortoise), hare = next(next(hare)), ++dist);
pair<int,int> cur(t0, t1);
for(int i = 0; i < n%dist; ++i){
cur = next(cur); }
g << (cur.first);
return 0; }