Cod sursa(job #3290371)

Utilizator solotpaulSolot Paul solotpaul Data 30 martie 2025 16:01:35
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

#define MOD (666013LL)

ifstream fin("iepuri.in");
ofstream fout("iepuri.out");

vector<size_t> mul(vector<size_t>& a, vector<size_t>& b) {
	vector<size_t> res(9);
	for (size_t i = 0; i < 3; ++i) {
		for (size_t j = 0; j < 3; ++j) {
			for (size_t k = 0; k < 3; ++k) {
				res[i * 3 + j] += a[i * 3 + k] * b[k * 3 + j] % MOD;
			}
		}
	}
	return res;
}

vector<size_t> exp(vector<size_t> a, size_t b) {
	if (b == 1) {
		return a;
	}
	if ((b & 1) == 0) {
		auto x = exp(a, b >> 1);
		return mul(x, x);
	} else {
		auto x = exp(a, b >> 1);
		auto left = mul(a, x);
		return mul(left, x);
	}
}

void solve() {
	size_t x, y, z, a, b, c, n;
	fin >> x >> y >> z >> a >> b >> c >> n;
	vector<size_t> mat = {0, 1, 0, 0, 0, 1, c, b, a};
	mat = exp(mat, n - 2);
	fout << (mat[6] * x + mat[7] * y + mat[8] * z) % MOD << '\n';
}

int main() {
	size_t t;
	fin >> t;
	while (t) {
		solve();
		--t;
	}
	return 0;
}