Cod sursa(job #3333142)

Utilizator prodsevenStefan Albu prodseven Data 11 ianuarie 2026 13:24:03
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream cin("iepuri.in");
ofstream cout("iepuri.out");

int t;
int x, y, z, a, b, c, n;
vector<vector<int>> cnst(3, vector<int>(3, 0)), ans(3, vector<int>(3, 0));
const int MOD = 666013;

void mul(vector<vector<int>> &p, vector<vector<int>> &q) {
	vector<vector<int>> r(3, vector<int>(3, 0));
	for (int k = 0 ; k < 3 ; ++k) {
		for (int j = 0 ; j < 3 ; ++j) {
			for (int i = 0 ; i < 3 ; ++i) {
				r[k][j] = (r[k][j] + ((1LL * p[k][i] * q[i][j]) % MOD)) % MOD;
			}
		}
	}
	p = r;
}

void exp(int power) {
	while (power) {
		if (power % 2) mul(ans, cnst);
		mul(cnst, cnst);
		power /= 2; 
	}
}

void reset() {
	cnst.assign(3, vector<int>(3, 0));
	ans.assign(3, vector<int>(3, 0));
}

int main() {
	cin >> t;
	while (t--) {
		cin >> x >> y >> z >> a >> b >> c >> n;
		cnst[1][0] = cnst[2][1] = 1;
		cnst[0][2] = c;
		cnst[1][2] = b;
		cnst[2][2] = a;
		ans[0][0] = x;
		ans[0][1] = y;
		ans[0][2] = z;
		exp(n - 2);
		cout << ans[0][2] << "\n";
		reset();
	}
	return 0;
}