Cod sursa(job #2716231)

Utilizator maraboneaMara Bonea marabonea Data 4 martie 2021 20:53:47
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
/**
*/
#include <fstream>
#define MOD 666013
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
int t,Z[3][3],Sol[3][3];
int x,y,z,a,b,c,n;
void Multiply(int A[3][3],int B[3][3])
{
    long long C[3][3];
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            C[i][j] = 0;
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            {
               for(int k = 0; k < 3; ++k)
                    C[i][j] = (C[i][j] + 1LL * A[i][k] * B[k][j])%MOD;

            }

    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            A[i][j] = C[i][j];
}
void iepuri(int x,int y,int z,int a,int b,int c,int n)
{
     for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            Z[i][j] =Sol[i][j]= 0;
     Z[0][0] = a;
     Z[0][1] =  1;
     Z[1][0] = b;
     Z[2][0] = c;
     Z[1][2] = 1;
    Sol [0][0] =  Sol [1][1]=  Sol [2][2]=1;
    n=n-2;
    while(n)
    {
        if(n % 2)
        {
            Multiply(Sol,Z);
        }
        Multiply(Z,Z);
        n = n/ 2;
    }
    fout<<(1LL*z*Sol[0][0]+1LL*y*Sol[1][0]+1LL*x*Sol[2][0])%MOD << endl;

}
void read()
{
    fin>>t;
    while(t)
    {
        fin>>x>>y>>z>>a>>b>>c>>n;
        iepuri(x,y,z,a,b,c,n);
        t--;
    }
}

int main()
{
    read();

   return 0;
}