Cod sursa(job #1459797)

Utilizator mouse_wirelessMouse Wireless mouse_wireless Data 10 iulie 2015 19:12:55
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

typedef long long LL;

#define MODNR 666013

class Matrix {
private:
	int a[3][3];
public:
	LL at(int x, int y) {
		return LL(a[x][y]);
	}
	Matrix() {}
	Matrix(int b[3][3]) {
		for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			a[i][j] = b[i][j];
	}
	Matrix operator*(Matrix &M) {
		Matrix res;
		for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) {
			int c = 0;
			for (int k = 0; k < 3; k++)
				c += (this->at(i, k)*M.at(k, j)) % MODNR;
			res.a[i][j] = c;
		}
		return res;
	}
	Matrix pow(int p) {
		if (p == 1)
			return *this;
		Matrix aux = this->pow(p / 2);
		if (p % 2)
			return aux*aux*(*this);
		return aux*aux;
	}
};

int main() {
	freopen("iepuri.in", "r", stdin);
	freopen("iepuri.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while (T--) {
		int X, Y, Z, A, B, C, N;
		scanf("%d%d%d%d%d%d%d", &X, &Y, &Z, &A, &B, &C, &N);
		int m[3][3] = { 0, 0, C, 1, 0, B, 0, 1, A };
		Matrix M = Matrix(m).pow(N - 2);
		int h[3][3] = { X, Y, Z, 0, 0, 0, 0, 0, 0 };
		Matrix H = Matrix(h)*M;
		printf("%d\n", int(H.at(0, 2)));
	}
	return 0;
}