Pagini recente » Cod sursa (job #442683) | Cod sursa (job #2773513) | Cod sursa (job #1814252) | Cod sursa (job #1213289) | Cod sursa (job #2636995)
#include <bits/stdc++.h>
#define newline '\n'
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
///**********************
const int MOD = 666013;
int n, x, y, z, a, b, c;
int ratiomat[4][4];
void multMat(int a[][4], int b[][4]) {
int r[4][4] = {};
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
r[i][j] = (1LL * r[i][j] + a[i][k] * b[k][j]) % MOD;
memcpy(a, r, sizeof(r));
}
void powLog(int p) {
int r[4][4] = {
{1},
{0, 1},
{0, 0, 1}
};
while (p) {
if (p & 1)
multMat(r, ratiomat);
multMat(ratiomat, ratiomat);
p >>= 1;
}
memcpy(ratiomat, r, sizeof(r));
}
void solve() {
memset(ratiomat, 0, sizeof(ratiomat));
ratiomat[1][0] = ratiomat[2][1] = 1;
fin >> x >> y >> z >> a >> b >> c >> n;
int inimat[4][4] = {{x, y, z}};
ratiomat[0][2] = c;
ratiomat[1][2] = b;
ratiomat[2][2] = a;
powLog(n - 2);
multMat(inimat, ratiomat);
fout << inimat[0][2] << newline;
}
int main() {
int q;
for (fin >> q; q--;)
solve();//*/
return 0;
}