Cod sursa(job #2854594)

Utilizator rares89_Dumitriu Rares rares89_ Data 21 februarie 2022 15:18:06
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>
#define MOD 666013

using namespace std;

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

int t, x, y, z, a, b, c, n;	
 
void inmultireMat(int a[3][3], int b[3][3]) {
    int rez[3][3];
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            rez[i][j] = (1LL * a[i][0] * b[0][j] + 1LL * a[i][1] * b[1][j] + 1LL * a[i][2] * b[2][j]) % MOD;
        }
    }
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            a[i][j] = rez[i][j];
        }
    }
}

int main() {
    fin >> t;
    while(t > 0) {
        fin >> x >> y >> z >> a >> b >> c >> n;
        int sol[3][3] = {
            {0, 1, 0},
            {0, 0, 1},
            {c, b, a}
        };
        int aux[3][3] = {
            {0, 1, 0},
            {0, 0, 1},
            {c, b, a}
        };
        n--;
        while(n > 0) {
            if(n % 2 != 0) {
                inmultireMat(sol, aux);
            }
            inmultireMat(aux, aux);
            n /= 2;
        }
        int ans = (1LL * sol[0][0] * x + 1LL * sol[0][1] * y + 1LL * sol[0][2] * z) % MOD;
        fout << ans << "\n";
        t--;
    }
    fin.close();
    return 0;
}