Pagini recente » Cod sursa (job #2260631) | Cod sursa (job #1948048) | Cod sursa (job #2169787) | Cod sursa (job #1265835) | Cod sursa (job #3208203)
#include <fstream>
#define MOD 666013
#define ll long long int
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
int T,X,Y,Z,A,B,C,N;
ll M[5][5],F[5][5],P[5][5],Mc[5][5];
void putere_mat(ll M[5][5], int N);
void produs_mat(ll A[5][5], ll B[5][5]);
void copie(ll A[5][5], ll B[5][5]);
void zero_mat(ll M[5][5]);
int main()
{
int i;
fin>>T;
for(i=1; i<=T; i++)
{
fin>>X>>Y>>Z>>A>>B>>C>>N;
zero_mat(F);
zero_mat(M);
F[1][1]=X; F[1][2]=Y; F[1][3]=Z;
M[2][1]=1; M[3][2]=1;
M[1][3]=C; M[2][3]=B; M[3][3]=A;
putere_mat(M,N-1);
produs_mat(F,M);
fout<<F[1][1]<<'\n';
}
return 0;
}
void putere_mat(ll M[5][5], int N)
{
copie(Mc,M);
while(N)
{
if(N%2==1) produs_mat(M,Mc);
produs_mat(Mc,Mc);
N/=2;
}
}
void copie(ll A[5][5], ll B[5][5])
{
int i,j;
for(i=1; i<=3; i++)
for(j=1; j<=3; j++)
A[i][j]=B[i][j];
}
void produs_mat(ll A[5][5], ll B[5][5])
{
int i,j,k;
zero_mat(P);
for(i=1; i<=3; i++)
for(j=1; j<=3; j++)
for(k=1; k<=3; k++)
P[i][j]=(P[i][j]+(A[i][k]*B[k][j])%MOD)%MOD;
copie(A,P);
}
void zero_mat(ll A[5][5])
{
int i,j;
for(i=1; i<=3; i++)
for(j=1; j<=3; j++)
A[i][j]=0;
}