Cod sursa(job #2407109)

Utilizator AndoneAlexandruAndone Alexandru AndoneAlexandru Data 16 aprilie 2019 15:17:38
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <cstring>
#define MOD 666013
using namespace std;

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

void inmultire(int a[5][5], int b[5][5]) {
    int aux[5][5];
    memset(aux, 0, sizeof(aux));

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j)
            for (int k = 0; k < 3; ++k)
                aux[i][j] += (1ll * a[i][k] * b[k][j]) % MOD;
    }

    for (int i = 0; i < 5; ++i)
        for (int j = 0; j < 5; ++j)
            a[i][j] = aux[i][j];
}

int main() {
    int n;
    in >> n;

    for (int q = 0; q < n; ++q) {
        int x, y, z, a, b, c, zile;

        in >> x >> y >> z;
        in >> a >> b >> c;
        in >> zile;

        int mat[5][5] = {{0, 0, c}, {1, 0, b}, {0, 1, a}};
        int r[5][5] = {{x, y, z}, {1, 1, 1}, {1, 1, 1}};

        while (zile) {
            if (zile % 2 == 1)
                inmultire(r, mat);
            inmultire(mat, mat);
            zile /= 2;
        }

        //int fib[5][5] = {{x, y, z}, {0, 0, 0}, {0, 0, 0}};

        //inmultire(fib, r);

        out << r[0][0] << '\n';
    }
    return 0;
}