Pagini recente » Cod sursa (job #2847624) | Cod sursa (job #2627725) | Cod sursa (job #2941796) | Cod sursa (job #3032947) | Cod sursa (job #2368547)
#include <fstream>
#include <cstring>
using namespace std;
#define FILE_NAME "iepuri"
ifstream in (FILE_NAME".in");
ofstream out(FILE_NAME".out");
const int MOD = 666013;
void multMat(int A[3][3], int B[3][3])
{
int C[3][3] = {};
for(int i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j)
for(int k = 0; k < 3; ++k)
C[i][j] = (C[i][j] + 1LL * A[i][k] * B[k][j]) % MOD;
memcpy(A, C, 3 * 3 * sizeof(int));
}
void powMat(int M[3][3], int exp)
{
int Result[3][3] = {{1, 0, 0},
{0, 1, 0},
{0, 0, 1}};
while(exp)
{
if(exp&1)
multMat(Result, M);
multMat(M, M);
exp >>= 1;
}
memcpy(M, Result, 3 * 3 * sizeof(int));
}
int main()
{
int T;
in >> T;
while(T--)
{
int X, Y, Z, A, B, C, N;
in >> X >> Y >> Z;
in >> A >> B >> C;
int M[3][3] = {{0, 0, C},
{1, 0, B},
{0, 1, A}};
in >> N;
powMat(M, N-2);
out << (X * M[0][2] % MOD + Y * M[1][2] % MOD + Z * M[2][2] % MOD) % MOD << '\n';
}
return 0;
}