Pagini recente » Cod sursa (job #3003616) | Cod sursa (job #692873) | Cod sursa (job #1977920) | Cod sursa (job #2759287) | Cod sursa (job #2665608)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
typedef long long lint;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const lint modit = 666013;
struct mat{
int w, h;
lint m[6][6];
};
void deb(mat ma){
for(int y = 0; y < ma.h; ++y){
for(int x = 0; x < ma.w; ++x){
cout << ma.m[y][x] << " ";
}
cout << "\n";
}
cout << "\n";
}
mat id3 = {3,3,{{1,0,0},{0,1,0},{0,0,1}}};
mat matmult(mat &lhs, mat &rhs){
mat r;
r.w = rhs.w;
r.h = lhs.h;
for(int y = 0; y < lhs.h; ++y){
for(int x = 0; x < rhs.w; ++x){
r.m[y][x] = 0;
for(int k = 0; k < lhs.w; ++k){
r.m[y][x] += lhs.m[y][k]*rhs.m[k][x];
r.m[y][x] %= modit;
}
}
}
return r;
}
mat matpow(mat &lhs, lint p){
mat r = id3;
mat kp = lhs;
for(lint i = 1; i <= p; i<<=1){
if(p&i){
r = matmult(r, kp);
}
kp = matmult(kp, kp);
}
return r;
}
void readsolve(){
lint X, Y, Z, A, B, C, N;
fin>>X>>Y>>Z>>A>>B>>C>>N;
mat M = {3,3,{{0,0,C},{1,0,B},{0,1,A}}};
mat Q = {3,1,{{X,Y,Z}}};
M = matpow(M, N-2);
mat ans = matmult(Q, M);
fout << ans.m[0][2] << "\n";
}
int main(){
// ios_base::sync_with_stdio(false);
int t;fin >> t;
for(int i = 0; i < t; ++i){
readsolve();
}
return 0;
}