Pagini recente » Cod sursa (job #1937615) | Cod sursa (job #155875) | Cod sursa (job #1369325) | Cod sursa (job #837867) | Cod sursa (job #1807221)
/// Problema "Iepuri" - InfoArena
#include <cstdio>
#include <algorithm>
#define in "iepuri.in"
#define out "iepuri.out"
#define MOD 666013
using namespace std;
int T, A, B, C, X, Y, Z, N;
struct matrice
{
int mat[4][4];
} aux, null, ans;
inline void init()
{
aux.mat[1][1] = 0;
aux.mat[1][2] = 0;
aux.mat[1][3] = C;
aux.mat[2][1] = 1;
aux.mat[2][2] = 0;
aux.mat[2][3] = B;
aux.mat[3][1] = 0;
aux.mat[3][2] = 1;
aux.mat[3][3] = A;
null.mat[1][1] = 1;
null.mat[1][2] = 0;
null.mat[1][3] = 0;
null.mat[2][1] = 0;
null.mat[2][2] = 1;
null.mat[2][3] = 0;
null.mat[3][1] = 0;
null.mat[3][2] = 0;
null.mat[3][3] = 1;
}
matrice inmultire(const matrice &M1, const matrice &M2)
{
matrice sol;
for(int i = 1; i<= 3; ++i)
{
for(int j = 1; j<= 3; ++j)
{
sol.mat[i][j] = 0;
for(int k = 1; k<= 3; ++k)
{
sol.mat[i][j] = (sol.mat[i][j] + 1LL*M1.mat[i][k]*M2.mat[k][j])%MOD;
}
}
}
return sol;
}
matrice power(const matrice &base, const int &Exp)
{
matrice sol = null, tmp = base;
int pw = Exp;
for( ; pw; pw >>= 1)
{
if(pw&1)
{
sol = inmultire(sol, tmp);
}
tmp = inmultire(tmp, tmp);
}
return sol;
}
int main()
{
freopen(in, "r", stdin);
freopen(out, "w", stdout);
scanf("%d", &T);
for( ; T; --T)
{
scanf("%d %d %d %d %d %d %d", &X, &Y, &Z, &A, &B, &C, &N);
init();
ans = power(aux, N-2);
printf("%d\n", (1LL*X*ans.mat[1][3] + 1LL*Y*ans.mat[2][3] + 1LL*Z*ans.mat[3][3])%MOD);
}
return 0;
}