Pagini recente » Cod sursa (job #1548341) | Cod sursa (job #3138516) | Cod sursa (job #1613516) | Cod sursa (job #2899687) | Cod sursa (job #3174257)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
const int MOD = 666013;
int T, x, y, z, a, b, c, n;
int A[3][3], I[3][3];
ifstream f("iepuri.in");
ofstream g("iepuri.out");
void multmat(int a[][3], int b[][3])
{
int c[3][3];
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
{
c[i][j] = 0;
for(int k = 0; k < 3; k++)
c[i][j] = (c[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
}
memcpy(a, c, sizeof(c));
}
void powlg(int p)
{
while(p)
{
if(p & 1)
multmat(I, A);
multmat(A, A);
p >>= 1;
}
}
void prel()
{
A[1][0] = 1;
A[2][1] = 1;
A[0][2] = c;
A[1][2] = b;
A[2][2] = a;
I[0][0] = 1;
I[1][1] = 1;
I[2][2] = 1;
}
void sterge()
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
A[i][j] = I[i][j] = 0;
}
int main()
{
f >> T;
while(T--)
{
f >> x >> y >> z >> a >> b >> c >> n;
prel();
powlg(n - 2);
g << (1LL * I[0][2]*x + I[1][2]*y + I[2][2]*z) % MOD << '\n';
sterge();
}
return 0;
}