Cod sursa(job #3335882)

Utilizator hiAvidMihaly David-Gabriel hiAvid Data 23 ianuarie 2026 19:42:55
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <fstream>
#define mod 666013
using namespace std;
ifstream in("iepuri.in");
ofstream out("iepuri.out");

int C[4][4], rez[4][4], aux[4][4];

void im(int op[4][4], int m[4][4])
{
    for (int i=1;i<=3;i++)
        for (int j=1;j<=3;j++)
        {
            aux[i][j]=0;
            for (int k=1;k<=3;k++)
                aux[i][j] += (1LL*op[i][k]*m[k][j]) % mod;
        }
}

void expo(int m[4][4], int e)
{
    while (e!=1)
    {
        if (e%2==0)
        {
            e/=2;
            im(m, m);
            for (int i=1;i<=3;i++)
                for (int j=1;j<=3;j++)
                    m[i][j] = aux[i][j];
        }
        else
        {
            e--;
            im(m, rez);
            for (int i=1;i<=3;i++)
                for (int j=1;j<=3;j++)
                    rez[i][j] = aux[i][j];
        }
    }
    im(m, rez);
    for (int i=1;i<=3;i++)
        for (int j=1;j<=3;j++)
            rez[i][j] = aux[i][j];
}

int main()
{
    int n, t, a, b, c, x, y, z;
    in >> t;
    for (int g=1;g<=t;g++)
    {
        in >> x >> y >> z >> a >> b >> c >> n;
        C[1][1] = 0; C[1][2] = 1; C[1][3] = 0;
        C[2][1] = 0; C[2][2] = 0; C[2][3] = 1;
        C[3][1] = c; C[3][2] = b; C[3][3] = a;
        for (int i=1;i<=3;i++)
            for (int j=1;j<=3;j++)
                rez[i][j]=0;
        rez[1][1] = rez[2][2] = rez[3][3] = 1;
        expo(C, n-2);
        out << ((1LL*x*rez[3][1])%mod + (1LL*y*rez[3][2])%mod + (1LL*z*rez[3][3])%mod)%mod << "\n";
    }
    return 0;
}