Pagini recente » Cod sursa (job #1043743) | Cod sursa (job #2631020) | Cod sursa (job #1679191) | Cod sursa (job #2749829) | Cod sursa (job #627312)
Cod sursa(job #627312)
#include <stdio.h>
#include <string.h>
#define MOD 666013
int M[4][4], now[4][4], sol[4][4];
inline void ProcessMatrix (int A, int B, int C)
{
M[1][1] = A; M[1][2] = B; M[1][3] = C;
M[2][1] = 1; M[2][2] = 0; M[2][3] = 0;
M[3][1] = 0; M[3][2] = 1; M[3][3] = 0;
}
void Multiplication (int A[][4], int B[][4])
{
int i, j, k;
memset (sol, 0, sizeof (sol));
for (i = 1; i <= 3; i ++)
for (j = 1; j <= 3; j ++)
for (k = 1; k <= 3; k ++)
sol[i][j] = (sol[i][j] + A[i][k] * B[k][j]) % MOD;
memcpy (now, sol, sizeof (now));
}
void FastPow (int pow)
{
if (pow == 1)
{
memcpy (now, M, sizeof (now));
return ;
}
FastPow (pow >> 1);
if (pow & 1)
{
Multiplication (now, now);
Multiplication (now, M);
}
else
Multiplication (now, now);
}
int main ()
{
int T, first, second, third, A, B, C, N;
freopen ("iepuri.in", "r", stdin);
freopen ("iepuri.out", "w", stdout);
scanf ("%d", &T);
while (T --)
{
scanf ("%d%d%d%d%d%d%d", &first, &second, &third, &A, &B, &C, &N);
ProcessMatrix (A, B, C);
FastPow (N - 2);
printf ("%d\n", (now[1][1] * third + now[1][2] * second + now[1][3] * first) % MOD);
}
return 0;
}