Pagini recente » Cod sursa (job #3184804) | Cod sursa (job #2616707) | Cod sursa (job #2978139) | Cod sursa (job #2973513) | Cod sursa (job #3299941)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
#define int long long
const int MOD = 666013;
typedef array<array<int, 3>, 3> mat3x3;
mat3x3 multiply(const mat3x3 &A, const mat3x3 &B)
{
mat3x3 ans = {{
{{0, 0, 0}},
{{0, 0, 0}},
{{0, 0, 0}}
}};
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++)
ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % MOD;
return ans;
}
mat3x3 power(mat3x3 base, int exp)
{
mat3x3 ans = {{
{{1, 0, 0}},
{{0, 1, 0}},
{{0, 0, 1}}
}};
while(exp != 0)
{
if(exp % 2 == 1)
ans = multiply(ans, base);
base = multiply(base, base);
exp /= 2;
}
return ans;
}
void solve_testcase()
{
int x, y, z, a, b, c, n;
fin >> x >> y >> z >> a >> b >> c >> n;
mat3x3 mat = {{
{{0, 1, 0}},
{{0, 0, 1}},
{{c, b, a}}
}};
mat = power(mat, n - 2);
fout << (mat[2][0] * x + mat[2][1] * y + mat[2][2] * z) % MOD << "\n";
}
signed main()
{
int t;
fin >> t;
while(t--)
solve_testcase();
fin.close();
fout.close();
return 0;
}