Cod sursa(job #3158680)

Utilizator andrei76Diaconescu Andrei andrei76 Data 19 octombrie 2023 16:58:26
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.06 kb
#include <iostream>
#include <fstream>

using namespace std;

// https://infoarena.ro/preoni-2005/runda-1/solutii
//I0=x I1=y I2=z

int main()
{
    int x, y, z, a, b, c, n, t, M[3][3], cM[3][3];
    ifstream fin("iepuri.in");
    ofstream fout("iepuri.out");
    fin>>t;
    for(int i = 1; i <= t; i++){
        fin>>x>>y>>z>>a>>b>>c>>n;
        M[0][0] = 0; M[0][1] = 1; M[0][2] = 0;
        M[1][0] = 0; M[1][1] = 0; M[1][2] = 1;
        M[2][0] = c; M[2][1] = b; M[2][2] = a;
        cM[0][0] = 0; cM[0][1] = 1; cM[0][2] = 0;
        cM[1][0] = 0; cM[1][1] = 0; cM[1][2] = 1;
        cM[2][0] = c; cM[2][1] = b; cM[2][2] = a;
        for(int j = 2; j <= n; j++){
            int newM[3][3];
            newM[0][0] = M[0][0]*cM[0][0] + M[0][1]*cM[1][0] + M[0][2]*cM[2][0];
            newM[0][1] = M[0][0]*cM[0][1] + M[0][1]*cM[1][1] + M[0][2]*cM[2][1];
            newM[0][2] = M[0][0]*cM[0][2] + M[0][1]*cM[1][2] + M[0][2]*cM[2][2];
            newM[1][0] = M[1][0]*cM[0][0] + M[1][1]*cM[1][0] + M[1][2]*cM[2][0];
            newM[1][1] = M[1][0]*cM[0][1] + M[1][1]*cM[1][1] + M[1][2]*cM[2][1];
            newM[1][2] = M[1][0]*cM[0][2] + M[1][1]*cM[1][2] + M[1][2]*cM[2][2];
            newM[2][0] = M[2][0]*cM[0][0] + M[2][1]*cM[1][0] + M[2][2]*cM[2][0];
            newM[2][1] = M[2][0]*cM[0][1] + M[2][1]*cM[1][1] + M[2][2]*cM[2][1];
            newM[2][2] = M[2][0]*cM[0][2] + M[2][1]*cM[1][2] + M[2][2]*cM[2][2];
            M[0][0] = newM[0][0]; M[0][1] = newM[0][1]; M[0][2] = newM[0][2];
            M[1][0] = newM[1][0]; M[1][1] = newM[1][1]; M[1][2] = newM[1][2];
            M[2][0] = newM[2][0]; M[2][1] = newM[2][1]; M[2][2] = newM[2][2];
        }
        fout<<(M[0][0]*x+M[0][1]*y+M[0][2]*z)%666013<<endl;
    }
   /* for(i = 1; i <= t; i++){
        fin>>x>>y>>z>>a>>b>>c>>n;
        unsigned long long int goku;
        for(j = 3; j <= n; j++){
            goku = a*z + b*y + c*x;
            x = y;
            y = z;
            z = goku;
        }
        fout<<goku%666013<<"\n";
        fout.flush();
    }
    return 0;*/

}