Pagini recente » Cod sursa (job #619515) | Cod sursa (job #2710065) | Cod sursa (job #2731054) | Cod sursa (job #1418021) | Cod sursa (job #3155135)
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
void mult(ll a[4][4], ll b[4][4], ll c[4][4]) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
c[i][j] = 0;
for (int k = 1; k <= 3; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
void copiaza(ll res[4][4], ll cop[4][4]) {
for (int i =1 ; i <= 3; i ++) {
for (int j = 1; j <= 3; j++)
res[i][j] = cop[i][j];
}
}
ll mat[4][4], res[4][4], aux[4][4];
void putere(ll n) {
while (n) {
if (n % 2 == 1) {
copiaza(aux, res);
mult(aux, mat, res);
}
n >>= 1;
copiaza(aux, mat);
mult(aux, aux, mat);
}
}
void init() {
for (int i =1 ; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
mat[i][j] = 0;
res[i][j] = 0;
aux[i][j] = 0;
}
res[i][i] = 1;
}
mat[2][1] = mat[3][2] = 1;
}
int main() {
int t;
fin >> t;
while (t--) {
ll a, b, c, x, y, z, n;
fin >> x >> y >> z >> a >> b >> c >> n;
init();
mat[1][3] = c;
mat[2][3] = b;
mat[3][3] = a;
putere(n - 2);
ll sol = res[3][3] * z + res[2][3] * y + res[1][3] * x;
fout << sol << '\n';
}
return 0;
}