Pagini recente » Cod sursa (job #2671897) | Cod sursa (job #2429676) | Cod sursa (job #52530) | Cod sursa (job #1886403) | Cod sursa (job #774827)
Cod sursa(job #774827)
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long int64;
const int MOD = 666013;
int n, t, x, y, z, a, b, c;
int64 mat[4][4], mat2[4][4];
void inmulteste(int64 a[][4], int64 b[][4])
{
int64 c[4][4];
memset(c, 0, sizeof(c));
for (int i = 1; i <= 3; ++i)
for (int j = 1; j <= 3; ++j)
for (int k = 1; k <= 3; ++k)
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
memcpy(a, c, sizeof(c));
}
void lgput(int x)
{
if (x == 1)
return;
if (!(x & 1)) {
lgput(x / 2);
inmulteste(mat, mat);
}
else {
lgput(x / 2);
inmulteste(mat, mat);
inmulteste(mat, mat2);
}
}
int main()
{
freopen ("iepuri.in", "r", stdin);
freopen ("iepuri.out", "w", stdout);
scanf("%d", &t);
for (int i = 1; i <= t; ++i) {
scanf("%d %d %d %d %d %d %d", &x, &y, &z, &a, &b, &c, &n);
memset(mat, 0, sizeof(mat));
mat[1][2] = mat[2][3] = 1;
mat[3][1] = c, mat[3][2] = b, mat[3][3] = a;
memcpy(mat2, mat, sizeof(mat));
lgput(n - 2);
printf("%lld\n", (mat[3][1] * x + mat[3][2] * y + mat[3][3] * z) % MOD);
}
}