Cod sursa(job #936839)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 8 aprilie 2013 21:47:59
Problema Iepuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <fstream>
#include <cstring>
#define LL long long
#define MOD 666013
using namespace std;
const char iname[] = "iepuri.in";
const char oname[] = "iepuri.out";
ifstream fin(iname);
ofstream fout(oname);
int X, Y, Z, L, H, S, N, Q;
LL Ans;
LL ANS[4][4], I[4][4], AUX[4][4], O[4][4];
void mul(LL A[4][4], LL B[4][4])
{
	int i, j, n; 
	LL ad;
	for (i = 1; i <= 3; ++i)
		for (j = 1; j <= 3; ++j) O[i][j] = B[i][j];
	for (i = 1; i <= 3; ++i)
		for (j = 1; j <= 3; ++j) AUX[i][j] = A[i][j];
	for (i = 1; i <= 3; ++i)
	{
		for (j = 1; j <= 3; ++j)
		{
			ad = 0;
			for (n = 1; n <= 3; ++n) 
				ad += 1LL * AUX[i][n] * O[n][j];
			A[i][j] = ad % MOD;
		}
	}
}
int main()
{
	fin >> Q;
	while (Q--)
	{
		fin >> X >> Y >> Z >> L >> H >> S >> N;
		memset (ANS, 0, sizeof(ANS));
		memset (I, 0, sizeof(I)); Ans = 0;
		ANS[1][1] = ANS[2][2] = ANS[3][3] = 1; Ans = 0;
		I[1][2] = I[2][3] = 1; 
		I[3][1] = S; I[3][2] = H; I[3][3] = L;
		N -= 2;
		for (; N > 0; N /= 2)
		{
			if (N % 2 == 1) mul(ANS, I);
			mul(I, I);
		}
		Ans = 1LL * (ANS[3][1] * X) % MOD + 1LL * (ANS[3][2] * Y) % MOD + 1LL * (ANS[3][3] * Z) % MOD;
		fout << Ans % MOD << '\n';
	}
	return 0;
}