Cod sursa(job #3227548)

Utilizator Gergo123Schradi Gergo Gergo123 Data 1 mai 2024 20:11:02
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int mod = 666013;
int t, x, y, z, a, b, c, n;

struct mat{
    int m[3][3];
};

mat nullmatrice = {
    {{1, 0, 0},
    {0, 1, 0},
    {0, 0, 1}}
};

mat produs(mat a, mat b){
    mat c;
    c.m[0][0] = (1LL * a.m[0][0] * b.m[0][0] + 1LL * a.m[0][1] * b.m[1][0] + 1LL * a.m[0][2] * b.m[2][0]) % mod;
    c.m[0][1] = (1LL * a.m[0][0] * b.m[0][1] + 1LL * a.m[0][1] * b.m[1][1] + 1LL * a.m[0][2] * b.m[2][1]) % mod;
    c.m[0][2] = (1LL * a.m[0][0] * b.m[0][2] + 1LL * a.m[0][1] * b.m[1][2] + 1LL * a.m[0][2] * b.m[2][2]) % mod;
    c.m[1][0] = (1LL * a.m[1][0] * b.m[0][0] + 1LL * a.m[1][1] * b.m[1][0] + 1LL * a.m[1][2] * b.m[2][0]) % mod;
    c.m[1][1] = (1LL * a.m[1][0] * b.m[0][1] + 1LL * a.m[1][1] * b.m[1][1] + 1LL * a.m[1][2] * b.m[2][1]) % mod;
    c.m[1][2] = (1LL * a.m[1][0] * b.m[0][2] + 1LL * a.m[1][1] * b.m[1][2] + 1LL * a.m[1][2] * b.m[2][2]) % mod;
    c.m[2][0] = (1LL * a.m[2][0] * b.m[0][0] + 1LL * a.m[2][1] * b.m[1][0] + 1LL * a.m[2][2] * b.m[2][0]) % mod;
    c.m[2][1] = (1LL * a.m[2][0] * b.m[0][1] + 1LL * a.m[2][1] * b.m[1][1] + 1LL * a.m[2][2] * b.m[2][1]) % mod;
    c.m[2][2] = (1LL * a.m[2][0] * b.m[0][2] + 1LL * a.m[2][1] * b.m[1][2] + 1LL * a.m[2][2] * b.m[2][2]) % mod;
    return c;
}

mat exponentiere(mat a, int n){
    if(n == 0) return nullmatrice;
    else{
        mat nr = exponentiere(a, n / 2);
        if(n % 2 == 1){
            return produs(a, produs(nr, nr));
        }
        else return produs(nr, nr);
    }
}

int main(){
    f >> t;
    while(t--){
        f >> x >> y >> z >> a >> b >> c >> n;
        mat matrice = {
            {{0, 1, 0},
            {0, 0, 1},
            {c, b, a}}
        };
        int sol = 0;
        mat rez = exponentiere(matrice, n);
        sol = 1ll * rez.m[0][0] * x % mod + 1ll * rez.m[0][1] * y % mod + 1ll * rez.m[0][2] * z % mod;
        g << sol % mod<< '\n';
    }
}