Cod sursa(job #1552178)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 17 decembrie 2015 12:29:01
Problema Rsir Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#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,
			(a * p.first * p.first + b * p.second * p.second + x * p.first + y * p.second + 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);

	vector<pair<int, int>> v(dist, make_pair(t0, t1));
	for(int i = 1; i < dist; ++i){
		v[i] = next(v[i-1]); }

	g << (v[n%dist].first);

	return 0; }