Pagini recente » Cod sursa (job #1708892) | Cod sursa (job #2470050) | Cod sursa (job #152847) | Cod sursa (job #561643) | Cod sursa (job #3151543)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
struct mat3x3{
long long m[4][4];
} init;
long long a,b,c;
mat3x3 genm(){
mat3x3 rez;
for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) rez.m[i][j] = 0;
return rez;
}
mat3x3 prod(mat3x3 m1, mat3x3 m2){
mat3x3 rez;
for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++){
rez.m[i][j] = 0;
for(int k = 0; k < 3; k++){
rez.m[i][j] += (m1.m[i][k] * m2.m[k][j]) % 666013;
rez.m[i][j] %= 666013;
}
}
return rez;
}
mat3x3 exp(long long n){
mat3x3 rez;
if(n == 1){
return init;
}
if(n & 1){
rez = exp(n - 1);
return prod(rez,init);
}
else{
rez = exp(n / 2);
return prod(rez,rez);
}
}
void print(mat3x3 x){
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++) fout << x.m[i][j] << " ";
fout << "\n";
}
}
void geninit(){
init.m[0][0] = 0;
init.m[0][1] = 0;
init.m[0][2] = c;
init.m[1][0] = a;
init.m[1][1] = 0;
init.m[1][2] = b;
init.m[2][0] = 0;
init.m[2][1] = 1;
init.m[2][2] = a;
}
int main()
{
long long n,i,x,y,z,t;
fin >> t;
for(int e = 1; e <= t; e++){
fin >> x >> y >> z >> a >> b >> c >> n;
geninit();
mat3x3 r = exp(n - 2);
//print(r);
fout << (z * r.m[2][2] + y * r.m[1][2] + x * r.m[0][2]) % 666013 << "\n";
//fout << "\n\n\n";
}
return 0;
}
/*
(z0,z1,z2)
(0 0 c
1 0 b
0 1 a)
(0 0 c
1 0 b
0 1 a)
(z1,z2,z3)
z0,z1,z2
(0 c ac
0 b c+ab
1 a b+a2
z2,z3,z4
*/