Cod sursa(job #2767587)

Utilizator Edyci123Bicu Codrut Eduard Edyci123 Data 6 august 2021 20:25:47
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
#define MOD 666013
#define VI vector <vector <int>>

using namespace std;

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

int A, B, C, x, y, z, n;

void prod(VI a, VI b, VI& rez)
{
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
        {
            rez[i][j] = 0;
            for(int k = 0; k < 3; k++)
                rez[i][j] = (rez[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
        }
}

int main()
{
    int q;
    f >> q;

    while(q--)
    {
        f >> x >> y >> z >> A >> B >> C >> n;
        VI a = {{A, B, C}, {1, 0 ,0}, {0, 1, 0}};
        VI sol = {{1, 0 ,0}, {0, 1, 0}, {0, 0, 1}};
        n -= 2;
        while(n)
        {
            if(n % 2 == 1)
                prod(sol, a, sol), n--;
            prod(a, a, a);
            n /= 2;

        }
        g << (1LL * sol[0][0] * z + 1LL * sol[0][1] * y + 1LL * sol[0][2] * x) << "\n";
    }


    return 0;
}