Cod sursa(job #3283857)

Utilizator iulia_morariuIuli Morariu iulia_morariu Data 10 martie 2025 16:42:22
Problema Iepuri Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <iostream>
#include <fstream>
#include <vector>
//#include <bits/stdc++.h>
#define in fin
#define out fout

using namespace std;
using ll = long long;
const ll MOD = 666013;

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

ll A, B, C;

struct mat{
    ll m[3][3];
};

mat M = {
    { {0, 1, 0},
      {0, 0, 1},
      {0, 0, 0} }
};

mat inm(mat & a, mat & b){
    mat c = {
        { {0, 0, 0},
          {0, 0, 0},
          {0, 0, 0} }
    };

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                c.m[i][j] += (a.m[i][k] * b.m[k][j]) % MOD;
                c.m[i][j] %= MOD;
            }
        }
    }
    return c;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t; in >> t;
    for(int ii = 0; ii < t; ii++){
        ll X, Y, Z, N;
        in >> X >> Y >> Z >> A >> B >> C >> N;
        
        mat sol = {
            { {Z, Y, X},
              {0, 0, 0},
              {0, 0, 0} }
        };

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

        // cout << "sol : \n";
        // for(int i = 0; i < 3; i++){
        //     for(int j = 0; j < 3; j++) cout << sol.m[i][j] << " ";
        //     cout << '\n';
        // }

        for(int i = 3; i <= N; i++){
            sol = inm(sol, M);
        }

        // cout << "sol : \n";
        // for(int i = 0; i < 3; i++){
        //     for(int j = 0; j < 3; j++) cout << sol.m[i][j] << " ";
        //     cout << '\n';
        // }

        out << sol.m[0][0] % MOD << '\n';
   }

    return 0;
}