Cod sursa(job #2280732)

Utilizator andonis1616And Cuz andonis1616 Data 11 noiembrie 2018 02:36:38
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <fstream>
#define MODULO 666013
using namespace std;
ifstream in ("iepuri.in");
ofstream out ("iepuri.out");

int t,x,y,z,a,b,c,n;

struct matrice
{
    long long m[3][3];
    matrice()
    {
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                m[i][j]=0;
    }
    matrice operator*(matrice m2)
    {
        matrice finala=matrice ();
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<3;k++){
                    finala.m[i][j]=(finala.m[i][j]+m[i][k]*m2.m[k][j])%MODULO;
                }
            }
        }
        return finala;
    }
};

matrice A, B;
matrice unit = matrice( );

matrice mPow (matrice x, int n)
{
    if (n==0)
        return unit;
    matrice half = mPow (x, n/2);
    half = half * half;
    if (n%2)
        half = half * x;
    return half;

}

int main()
{
    unit.m[0][0] = unit.m[1][1] = unit.m[2][2]  = 1;
    int h=1;
    in>>t;
    for(h=1;h<=t;h++){
        in>>x>>y>>z>>a>>b>>c>>n;
        A=matrice();
        B=matrice();
        B.m[0][0] = 0; B.m[0][1] = 0; B.m[0][2] = c;
        B.m[1][0] = 1; B.m[1][1] = 0; B.m[1][2] = b;
        B.m[2][0] = 0; B.m[2][1] = 1; B.m[2][2] = a;
        A.m[0][0] = x; A.m[0][1] = y; A.m[0][2] = z;
        B=mPow(B,n-2);
        A=A*B;
        out<<A.m[0][2]<<'\n';
    }
    return 0;
}