Cod sursa(job #3355676)

Utilizator g.darius07Gheorghe Darius Nicolae g.darius07 Data 24 mai 2026 17:49:45
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 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 mult(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] % MOD;
}

int putere(int n) {
    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(n) {
        if(n % 2 == 0)
            mult(m, m), n /= 2;
        else mult(v, m), n--;
    }
    return v[0][2];
}

int main() {
    int t, n;
    f >> t;
    while(t--) {
        f >> x >> y >> z >> a >> b >> c >> n;
        g << putere(n - 2) << '\n';
    }
    f.close();
    g.close();
    return 0;
}