Pagini recente » Cod sursa (job #1209445) | Cod sursa (job #1397502) | Cod sursa (job #2189722) | Cod sursa (job #2918491) | Cod sursa (job #3192937)
#include <fstream>
using namespace std;
ifstream cin("iepuri.in");
ofstream cout("iepuri.out");
const int dim = 3, mod = 666013;
void copy_matrix(int A[3][3], int B[3][3])
{
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
A[i][j] = B[i][j];
}
void matrix_multiplication(int A[3][3], int B[3][3], int rez[3][3])
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
rez[i][j] = 0;
}
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
rez[i][j] = (rez[i][j] + 1ll * A[i][k] * B[k][j]) % mod;
}
}
}
}
void fast_exponentiation(int A[3][3], int ans[3][3], int exp)
{
int base[3][3];
copy_matrix(base, A), copy_matrix(ans, A);
exp--;
while (exp)
{
if ((exp & 1) != 0)
matrix_multiplication(ans, base, A), copy_matrix(ans, A);
matrix_multiplication(base, base, A), copy_matrix(base, A);
exp >>= 1;
}
}
void solve()
{
int x, y, z, a, b, c, n;
cin >> x >> y >> z >> a >> b >> c >> n;
int A[3][3] = { {a, b, c}, {1, 0, 0}, {0, 1, 0} }, X[] = { z, y, x }, ans[3][3];
fast_exponentiation(A, ans, n - 3 + 1);
int xn = 0;
for (int k = 0; k < 3; k++)
{
xn = (xn + 1ll * ans[0][k] * X[k]) % mod;
}
cout << xn << "\n";
}
int main()
{
int t;
cin >> t;
while (t--)
solve();
}