Cod sursa(job #3336828)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 26 ianuarie 2026 09:48:30
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.48 kb
#include <bits/stdc++.h>

using namespace std;

#define USE_STD_IO 0
#if USE_STD_IO
    #define fin cin
    #define fout cout
#else
    ifstream fin("iepuri.in");
    ofstream fout("iepuri.out");
#endif

typedef long long LL;
typedef LL Matrice[3][3];
const LL MOD = 666013;

Matrice a, c, put;
int x, y, z, va, vb, vc, n;

static inline void Inmul(Matrice a, Matrice b) {
    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] + a[i][k] * b[k][j] % MOD) % MOD;
            }
        }
    }
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            a[i][j] = c[i][j];
        }
    }
}

int main() {
    if(USE_STD_IO) ios_base::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);

    int t;
    fin >> t;
    while(t--) {
        fin >> x >> y >> z >> va >> vb >> vc >> n;

        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                put[i][j] = 0;
                a[i][j] = 0;
            }
        }

        put[0][0] = x;
        put[0][1] = y;
        put[0][2] = z;

        a[0][2] = vc;
        a[1][2] = vb;
        a[2][2] = va;
        a[1][0] = a[2][1] = 1;

        n -= 2;
        while(n) {
            if(n & 1) Inmul(put, a);
            Inmul(a, a);
            n >>= 1;
        }
        fout << put[0][2] << " ";
    }

    return 0;
}