Cod sursa(job #3314171)

Utilizator stefangr2008Grecu Stefan stefangr2008 Data 8 octombrie 2025 19:43:30
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <iostream>
#include <fstream>

using namespace std;
const int MOD = 666013;

int X, Y, Z, A, B, C;

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

void mulmat(int a[][3], int b[][3])
{
    long long c[3][3];
    int i, j, k;
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
        {
            c[i][j] = 0;
            for(k = 0; k < 3; k++)
                c[i][j] += (long long)a[i][k] * b[k][j];
        }
    for(j = 0; i < 3; i++)
        for(j = 0; j < 3; j++)
            a[i][j] = c[i][j] % MOD;
}

int puteremat(int p)
{
    int M[3][3] =
    {
        {0, 0, C},
        {1, 0, B},
        {0, 1, A}
    };
    int V[3][3] =
    {
        {X, Y, Z},
        {0, 0, 0},
        {0, 0, 0}
    };
    while(p)
    {
        if(p % 2)
            mulmat(V, M);
        mulmat(M, M);
        p /= 2;
    }
    return V[0][2];
}

int main()
{
    int T, N;
    f >> T;
    while(T--)
    {
        f >> X >> Y >> Z
          >> A >> B >> C
          >> N;
        g << puteremat(N - 2) << '\n';
    }
    f.close();
    g.close();
    return 0;
}