Pagini recente » Cod sursa (job #815944) | Cod sursa (job #1330403) | Cod sursa (job #392714) | Cod sursa (job #431714) | Cod sursa (job #2593640)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666013;
void prod(int p[3][3], int a[3][3], int b[3][3]){
int aux[3][3];
for(int i=0; i<3; i++)
for(int j=0; j<3; j++){
aux[i][j] = 0;
for(int k=0; k<3; k++)
aux[i][j] = (1LL * aux[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
}
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
p[i][j] = aux[i][j];
}
int rez[3][3];
void power(int n, int a, int b, int c){
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
rez[i][j] = (i == j);
int mat[3][3] = {{a, b, c}, {1, 0, 0}, {0, 1, 0}};
while(n){
if(n%2)
prod(rez, rez, mat);
prod(mat, mat, mat);
n /= 2;
}
}
int main()
{
int t,a,b,c,x,y,z,n;
fin >> t;
while(t--){
fin >> x >> y >> z >> a >> b >> c >> n;
power(n - 2, a, b, c);
fout << (1LL * rez[0][0] * z + 1LL * rez[0][1] * y + 1LL * rez[0][2] * x) % MOD << "\n";
}
return 0;
}