Cod sursa(job #1552190)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 17 decembrie 2015 12:38:49
Problema Rsir Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 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,
			((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; }