Cod sursa(job #2930062)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 27 octombrie 2022 13:52:04
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.73 kb
#include <bits/stdc++.h>

using namespace std;

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

#define int long long

int act[5][5],inm[5][5],aux[5][5];
int modulo = 666013;

signed main()
{
    int t;
    in >> t;
    while (t--)
    {
        int x,y,z,a,b,c,n;
        in >> x >> y >> z >> a >> b >> c >> n;
        act[1][1] = 1;
        act[1][2] = 0;
        act[1][3] = 0;
        act[2][1] = 0;
        act[2][2] = 1;
        act[2][3] = 0;
        act[3][1] = 0;
        act[3][2] = 0;
        act[3][3] = 1;

        inm[1][1] = 0;
        inm[1][2] = 1;
        inm[1][3] = 0;
        inm[2][1] = 0;
        inm[2][2] = 0;
        inm[2][3] = 1;
        inm[3][1] = c;
        inm[3][2] = b;
        inm[3][3] = a;

        while (n != 0)
        {
            if (n % 2 == 1)
            {
                for (int i = 1; i <= 3; i++)
                    for (int j = 1; j <= 3; j++)
                        for (int q = 1; q <= 3; q++)
                            aux[i][j] += act[i][q] * inm[q][j];
                for (int i = 1; i <= 3; i++)
                    for (int j = 1; j <= 3; j++)
                        act[i][j] = aux[i][j] % modulo,aux[i][j] = 0;
            }
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    for (int q = 1; q <= 3; q++)
                        aux[i][j] += inm[i][q] * inm[q][j];
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    inm[i][j] = aux[i][j] % modulo,aux[i][j] = 0;
            n /= 2;
        }

        int ans = (act[1][1] * x + act[1][2] * y + act[1][3] * z) % modulo;
        out << ans << '\n';
    }
    return 0;
}