Cod sursa(job #2586413)

Utilizator sulzandreiandrei sulzandrei Data 20 martie 2020 20:33:41
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.8 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <utility>
#include <cstring>

using namespace std;

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

#define ull long long int

#define MOD 666013
int mod(int a, int b)
{
    return (a*b)%MOD;
}
struct M
{
public :
    int a[3][3] ;

    M()
    {

    }

    M(int b[3][3])
    {
        for(int i = 0 ; i < 3 ; i++)
        {
            for(int j = 0 ; j <3 ; j++)
            {
                a[i][j] = b[i][j];
            }

        }


    }

    M(const M &p)
    {
        for(int i = 0 ; i < 3 ; i++)
        {
            for(int j = 0 ; j <3 ; j++)
            {
                a[i][j] = p.a[i][j];
            }
        }
    }



    M operator *(const M& right)
    {
        struct M res;

        int lin = 3;
        int col = 3;
        for(int i = 0 ; i < lin ; i++)
        {
            for(int j = 0 ; j <col ; j++)
            {
                int aij = 0;
                for(int k = 0 ; k < col ; k++)
                {
                    aij =  (aij + mod(a[i][k],right.a[k][j]))%MOD;
                }
                res.a[i][j] = aij;
            }
        }

        return res;

    }
};


int rabbit(int x, int y, int z,int a,int b, int c, int n)
{


    struct M base(new int[3][3]
    { {a,b,c}, {1,0,0}, {0,1,0}
    });


    struct M res(new int[3][3]
    { {1,0,0}, {0,1,0}, {0,0,1}
    });

    n -=2;

    while(n >0 )
    {

        if(n&1)
        {
            res = res*base;
        }

        base = base * base;
        n >>=1;
    }
    return (mod(z%MOD,res.a[0][0]%MOD)+ mod(y%MOD,res.a[0][1]%MOD) + mod(x%MOD,res.a[0][2]%MOD))%MOD;

}




int main ( )
{
    int t,X, Y, Z, A,B,C,N;
    in>>t;

    while(t--)
    {
        in>>X>>Y>>Z>>A>>B>>C>>N;
        out<<rabbit(X,Y,Z,A,B,C,N)<<'\n';
    }

    return 0;
}