Pagini recente » Cod sursa (job #2195677) | Cod sursa (job #1870997) | Cod sursa (job #654915) | Cod sursa (job #2062876) | Cod sursa (job #3316394)
#include <bits/stdc++.h>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
const int MOD = 666013;
struct Mat
{
int m[4][4];
};
const Mat I3 = {{
{0, 0, 0, 0},
{0, 1, 0, 0},
{0 ,0, 1, 0},
{0, 0, 0, 1}}};
Mat mat1 = {{
{0, 0, 0, 0},
{0, 0, 1, 0},
{0 ,0, 0, 1},
{0, 0, 0, 0}}};
Mat inmultire(Mat a, Mat b)
{
Mat res = {};
for(int i=1; i<=3; i++)
for(int j=1; j<=3; j++)
for(int k=1; k<=3; k++)
res.m[i][j] = (1LL * res.m[i][j] + 1LL*a.m[i][k] * b.m[k][j]) % MOD;
return res;
}
Mat putere(Mat x, int p)
{
Mat res = I3;
while(p)
{
if(p & 1)
res = inmultire(res, x);
x = inmultire(x, x);
p >>= 1;
}
return res;
}
int main()
{
int nr_teste;
f >> nr_teste;
while(nr_teste--)
{
/// X Y Z A B C N
int mat2[4];
for(int i=1; i<=3; i++)
f >> mat2[i]; /// X Y Z
for(int i=1; i<=3; i++)
f >> mat1.m[3][3-i+1];
int n;
f >> n;
Mat a = putere(mat1, n);
int res = 0;
for(int i=1; i<=3; i++)
res = (1LL * res + 1LL * a.m[1][i] * mat2[i]) % MOD;
g << res << '\n';
}
}