Cod sursa(job #3325610)

Utilizator geeedavid susu geee Data 25 noiembrie 2025 20:11:15
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
using namespace std;

int x, y, z, a, b, c, M = 666013;

ifstream fin("iepuri.in");
ofstream fout("iepuri.out");

void m1(int A[][3], int B[][3]) {
    long long C[3][3];
    int i, j, k;

    for (i = 0; i < 3; ++i)
        for (j = 0; j < 3; ++j) {
            C[i][j] = 0;
            for (k = 0; k < 3; ++k)
                C[i][j] += 1LL * A[i][k] * B[k][j];
        }

    for (i = 0; i < 3; ++i)
        for (j = 0; j < 3; ++j)
            A[i][j] = C[i][j] % M;
}

int p(int n) {
    int A3[3][3] = {
        {0, 0, c},
        {1, 0, b},
        {0, 1, a}
    };

    int B3[3][3] = {
        {x, y, z},
        {0, 0, 0},
        {0, 0, 0}
    };

    while (n) {
        if (n & 1)
            m1(B3, A3);
        m1(A3, A3);
        n >>= 1;
    }

    return B3[0][2];
}

int main() {
    int t, n;
    fin >> t;

    while (t--) {
        fin >> x >> y >> z >> a >> b >> c >> n;
        fout << p(n - 2) << '\n';
    }

    return 0;
}