Cod sursa(job #3174287)

Utilizator AlbertPavPavalache Albert AlbertPav Data 24 noiembrie 2023 16:44:49
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
const int MOD = 666013;

int T, x, y, z, a, b, c, n;

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

void multmat(int a[][3], int b[][3])
{
    int c[3][3];
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
        {
            c[i][j] = 0;
            for(int k = 0; k < 3; k++)
                c[i][j] = (c[i][j] + 1LL * a[i][k] * b[k][j]%MOD) % MOD;
        }
    memcpy(a, c, sizeof(c));
}

int powlg(int p)
{
    int A[3][3] =
    {
        {0, 0, c},
        {1, 0, b},
        {0, 1, a}
    };
    int I[3][3] =
    {
        {1, 0, 0},
        {0, 1, 0},
        {0, 0, 1}
    };
    while(p)
    {
        if(p & 1)
            multmat(I, A);
        multmat(A, A);
        p >>= 1;
    }
    return (1LL * I[0][2]*x + 1LL*I[1][2]*y + 1LL*I[2][2]*z) % MOD;
}


int main()
{
    f >> T;
    while(T--)
    {
        f >> x >> y >> z >> a >> b >> c >> n;
        g<<powlg(n - 2)<<'\n';
    }
    return 0;
}