Pagini recente » Cod sursa (job #803792) | Cod sursa (job #2187683) | Cod sursa (job #540767) | Cod sursa (job #2096983) | Cod sursa (job #3330630)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666013;
int t;
struct matrice
{
long long mat[3][3];
void init()
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
mat[i][j] = 0;
}
};
matrice multiply(matrice a, matrice b)
{
matrice ans;
ans.init();
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
for(int k = 0; k < 3; k++)
{
ans.mat[i][j] = (ans.mat[i][j] + 1LL*a.mat[i][k] * b.mat[k][j]) % MOD;
}
}
}
return ans;
}
matrice log_pow(matrice a, long long put)
{
matrice iden;
iden.init();
for(int i = 0; i < 3; i++)
iden.mat[i][i] = 1;
while(put)
{
if(put & 1)
iden = multiply(iden,a);
a = multiply(a,a);
put >>= 1;
}
return iden;
}
void solve()
{
int n,x,y,z,a,b,c;
fin >> x >> y >> z >> a >> b >> c >> n;
matrice T;
T.init();
T.mat[0][0] = a;
T.mat[1][0] = 1;
T.mat[0][1] = b;
T.mat[2][1] = 1;
T.mat[0][2] = c;
matrice ans;
ans.init();
ans = log_pow(T,n-2);///stim pentru 0,1,2
long long rasp = 0;
rasp = (rasp + ans.mat[0][0] * z) % MOD;
rasp = (rasp + ans.mat[0][1] * y) % MOD;
rasp = (rasp + ans.mat[0][2] * x) % MOD;
fout << rasp << '\n';
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
fin >> t;
while(t--)
solve();
return 0;
}