Pagini recente » Cod sursa (job #2799787) | Cod sursa (job #1662365) | Cod sursa (job #1069466) | Cod sursa (job #1771111) | Cod sursa (job #3241726)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666.013;
struct matrice
{
long long v[3][3];
};
matrice multiplication(matrice a, matrice b)
{
matrice rez;
for (int row = 0; row < 3; row++)
{
for (int column = 0; column < 3; column++)
{
rez.v[row][column] = 0;
for (int i = 0; i < 3; i++)
rez.v[row][column] += a.v[row][i] * b.v[i][column];
rez.v[row][column] %= MOD;
}
}
return rez;
}
matrice putere(matrice a, int n)
{
matrice rez = {{{1, 0, 0},
{0, 1, 0},
{0, 0, 1}}};
while (n != 0)
{
if (n % 2 == 1)
rez = multiplication(rez, a);
a = multiplication(a, a);
n /= 2;
}
return rez;
}
void solve()
{
int x, y, z, a, b, c, n;
fin >> x >> y >> z >> a >> b >> c >> n;
matrice m = {{{a, b, c},
{1, 0, 0},
{0, 1, 0}}};
matrice p = putere(m, n - 2);
fout << (p.v[0][0] * z + p.v[0][1] * y + p.v[0][2] * x) % MOD << "\n";
}
int main()
{
int t;
fin >> t;
while(t--)
solve();
return 0;
}