Pagini recente » Cod sursa (job #443937) | Cod sursa (job #2913313) | Cod sursa (job #2157735) | Cod sursa (job #851473) | Cod sursa (job #2789240)
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin( "iepuri.in" );
ofstream fout( "iepuri.out" );
const int MMAX = 5;
const int MOD = 666013;
struct matrix{
int mat[MMAX + 2][MMAX + 2];
int l, c;
};
matrix Multiply( matrix A, matrix B ){
int i, j, k;
matrix M;
for( i = 1; i <= A.l; ++i )
for( j = 1; j <= B.c; ++j )
M.mat[i][j] = 0;
M.l = A.l; M.c = B.c;
for( i = 1; i <= A.l; ++i )
for( j = 1; j <= B.c; ++j )
for( k = 1; k <= A.c; ++k )
M.mat[i][j] = (M.mat[i][j] + (A.mat[i][k] * B.mat[k][j]) % MOD) % MOD;
return M;
}
matrix LgPut( matrix A, int b ){
matrix P, P1, A1;
P.l = P.c = 3;
P.mat[1][1] = 1; P.mat[1][2] = 0; P.mat[1][3] = 0;
P.mat[2][1] = 0; P.mat[2][2] = 1; P.mat[2][3] = 0;
P.mat[3][1] = 0; P.mat[3][2] = 0; P.mat[3][3] = 1;
while( b > 0 ){
if( b % 2 == 1 ) {
P1 = Multiply(P, A);
P = P1;
}
A1 = Multiply(A, A);
A = A1;
b /= 2;
}
return P;
}
signed main() {
int x, y, z, a, b, c, n, t;
fin >> t;
while( t-- ) {
fin >> x >> y >> z >> a >> b >> c >> n;
matrix A, B, B1;
A.l = 1; A.c = 3;
A.mat[1][1] = x; A.mat[1][2] = y; A.mat[1][3] = z;
B.l = B.c = 3;
B.mat[1][1] = 0; B.mat[1][2] = 0; B.mat[1][3] = c;
B.mat[2][1] = 1; B.mat[2][2] = 0; B.mat[2][3] = b;
B.mat[3][1] = 0; B.mat[3][2] = 1; B.mat[3][3] = a;
B1 = LgPut(B, n - 2); B = B1;
B1 = Multiply(A, B);
fout << B1.mat[1][3] << "\n";
}
return 0;
}