Cod sursa(job #2058602)

Utilizator MrRobotMrRobot MrRobot Data 5 noiembrie 2017 21:41:45
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.97 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

ifstream fin("iepuri.in");
ofstream fout("iepuri.out");



void inm_matr(int A[3][3], int B[3][3])
{
    long long AB[3][3];
    int i, j, k;
    for(i = 0; i < 3; i++)
        for(j = 0; j < 3; j++)
        {
            AB[i][j]=0;
            for(k = 0; k < 3; k++)
                AB[i][j] += ( (long long)(A[i][k] * B[k][j]) % 666013 );
        }
    for(i = 0; i < 3; i++)
        for(j = 0; j < 3; j++)
            A[i][j] = AB[i][j];

}

/*
void exp_log(long long M[3][3], int p)
{


    if (p%2 == 0 && p>0)
    {
        inm_matr(M);
        exp_log(M, p/2);
    }


    if (p%2 == 1 && p>1)
    {
        int i, j, k;
        int M_vechi[3][3];
        for(i = 0; i < 3; i++)
            for(j = 0; j < 3; j++)
                M_vechi[i][j] = M[i][j];

        inm_matr(M);
        exp_log(M, (p-1)/2);

        long long MP[3][3]={0,0};
        for(i = 0; i < 3; i++)
            for(j = 0; j < 3; j++)
                for(k = 0; k < 3; k++)
                    MP[i][j] += (M[i][k] * M_vechi[k][j] % 666013);
        for(i = 0; i < 3; i++)
            for(j = 0; j < 3; j++)
                M[i][j] = MP[i][j];
    }
}*/


int main()
{
    int T, X, Y, Z, A, B, C, N, i;
    fin>>T;
    for(i=1; i<=T; i++)
    {
        fin>>X>>Y>>Z>>A>>B>>C>>N;
        int M[3][3], XYZ[3][3];
        memset(XYZ, 0, sizeof(XYZ));
        memset(M, 0, sizeof(M));

        /*M[0][1]=1;
        M[1][2]=1;
        M[2][0]=C;
        M[2][1]=B;
        M[2][2]=A;*/

        M[1][0]=1;
        M[2][1]=1;
        M[0][2]=C;
        M[1][2]=B;
        M[2][2]=A;

        XYZ[0][0]=X;
        XYZ[0][1]=Y;
        XYZ[0][2]=Z;
        //exp_log(M, N);

        while ( N )
        {
            if(N%2 == 1)
                inm_matr(XYZ, M);
            inm_matr(M, M);
            N /= 2;
        }
        fout<<XYZ[0][0]<<endl;
    }
}