Pagini recente » Cod sursa (job #1445363) | Cod sursa (job #2135927) | Cod sursa (job #106832) | Cod sursa (job #60687) | Cod sursa (job #3266323)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 666013;
int t, x, y, z, a, b, c, n;
long long mt[2][4], w[4][4];
void reset() {
memset(w, 0, sizeof(w));
mt[1][1] = x;
mt[1][2] = y;
mt[1][3] = z;
w[2][1] = w[3][2] = 1;
w[1][3] = c;
w[2][3] = b;
w[3][3] = a;
}
void prod(int limit, long long a[4][4], long long b[4][4]) {
long long res[4][4];
memset(res, 0, sizeof(res));
for (int i = 1; i <= limit; ++i) {
for (int j = 1; j <= 3; ++j) {
for (int k = 1; k <= 3; ++k) {
res[i][j] = (res[i][j] + (a[i][k] * b[k][j])) % MOD;
}
}
}
for (int i = 1; i <= limit; ++i) {
for (int j = 1; j <= 3; ++j) {
a[i][j] = res[i][j];
}
}
}
void exp(long long w[4][4], int pwr) {
long long res[4][4];
memset(res, 0, sizeof(res));
res[1][1] = res[2][2] = res[3][3] = 1;
while (pwr != 0) {
if (pwr & 1 == 1) {
prod(3, res, w);
}
prod(3, w, w);
pwr >>= 1;
}
for (int i = 1; i <= 3; ++i) {
for (int j = 1; j <= 3; ++j) {
w[i][j] = res[i][j];
}
}
}
int main() {
ifstream cin("iepuri.in");
ofstream cout("iepuri.out");
cin >> t;
while (t--) {
cin >> x >> y >> z >> a >> b >> c >> n;
reset();
exp(w, n - 1 - 1);
prod(1, mt, w);
cout << mt[1][3] << "\n";
}
}