Pagini recente » Cod sursa (job #1405075) | Cod sursa (job #1892586) | Cod sursa (job #2462229) | Cod sursa (job #1075750) | Cod sursa (job #3174283)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
const int MOD = 666013;
int T, x, y, z, a, b, c, n;
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) % MOD;
}
memcpy(a, c, sizeof(c));
}
int powlg(int p)
{
int A[3][3] =
{
{0, 0, c},
{1, 0, b},
{0, 1, a}
};
int I[3][3] =
{
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
};
while(p)
{
if(p & 1)
multmat(I, A);
multmat(A, A);
p >>= 1;
}
return (1LL * I[0][2]*x + I[1][2]*y + I[2][2]*z) % MOD;
}
int main()
{
f >> T;
while(T--)
{
f >> x >> y >> z >> a >> b >> c >> n;
g<<powlg(n - 2)<<'\n';
}
return 0;
}