Cod sursa(job #3159718)

Utilizator AswVwsACamburu Luca AswVwsA Data 21 octombrie 2023 20:34:30
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
//oftica si durere in suflet
#include <fstream>
#include <cmath>
#include <algorithm>
#define ll long long

using namespace std;

const int MOD = 666013;

struct matrice
{
    int a[3][3];
    matrice (int id = 0)
    {
        int i, j;
        for (i = 0; i < 3; i++)
            for (j = 0; j < 3; j++)
                if (id)
                    a[i][j] = (i == j);
                else
                    a[i][j] = 0;
    }
};

matrice operator *(matrice a, matrice b)
{
    matrice ans(0);
    int i, j, k;
    for (i = 0; i < 3; i++)
        for (j = 0; j < 3; j++)
            for (k = 0; k < 3; k++)
                ans.a[i][j] = (ans.a[i][j] + 1LL * a.a[i][k] * b.a[k][j] % MOD) % MOD;
    return ans;
}

matrice operator ^(matrice a, int b)
{
    matrice ans(1);
    while (b)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}


signed main()
{
    ifstream cin("iepuri.in");
    ofstream cout("iepuri.out");
    int t;
    cin >> t;
    while (t--)
    {
        int x, y, z, a, b, c, n;
        cin >> x >> y >> z >> a >> b >> c >> n;
        matrice ans(0);
        ans.a[0][0] = z;
        ans.a[0][1] = y;
        ans.a[0][2] = x;

        matrice op(0);
        op.a[0][0] = a;
        op.a[1][0] = b;
        op.a[2][0] = c;
        op.a[0][1] = 1;
        op.a[1][2] = 1;

        op = (op ^ (n - 2));
        ans = ans * op;

        cout << ans.a[0][0] << "\n";
    }
}