Cod sursa(job #3165620)

Utilizator alexvali23alexandru alexvali23 Data 6 noiembrie 2023 16:54:46
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#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 mul(int A[][3], int B[][3]) ///A<---A*B
{
    int C[3][3], i, j, k;
    for(i = 0; i < 3; i++)
        for(j = 0; j < 3; j++)
        {
            long long x = 0;
            for(k = 0; k < 3; k++)
                x += (long long)A[i][k] * B[k][j];
            C[i][j] = x % MOD;
        }
    memcpy(A, C, sizeof(C));
}
int putere(int n)
{
    int M[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(n > 0)
    {
        if(n % 2 == 0)
        {
            mul(M, M);
            n /= 2;
        }
        else
        {
            mul(I, M);
            n--;
        }
    }
    return ((long long)X * I[0][2] + (long long)Y * I[1][2] + (long long)Z * I[2][2]) % MOD;
}
int main()
{
    int T, N;
    f >> T;
    while(T--)
    {
        f >> X >> Y >> Z;
        f >> A >> B >> C;
        f >> N;
        g << putere(N - 2) << '\n';
    }
    return 0;
}