Cod sursa(job #3205505)

Utilizator AndyGooShooterDurlea Andrei AndyGooShooter Data 19 februarie 2024 20:22:42
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>
using namespace std;

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

int t, x, y, z, n;
int MOD = 666013;

struct Array {
    
    int a[3][3];
    int *operator [] (int i){
        return a[i];
    }

    Array operator * (Array b){

        Array c = {};
        for(int i = 0; i <= 2; i ++)
            for(int j = 0; j <= 2; j ++) 
                for(int k = 0; k <= 2; k ++) 
                    c[i][j] = (c[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
        return c;
    }
};
Array w,r;

int main()
{
    in >> t;
    while(t){
        t --;
        w = {{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}};
        r = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}};
      
        in >> x >> y >> z;
        in >> w[2][2];
        in >> w[1][2];
        in >> w[0][2];

        in >> n;

        while(n){

            // n >>= 1 inseamna n = n / 2;

            if(n & 1)
                r = r * w;

            w = w * w;
            n >>= 1;
        }
        out << (Array{{{x, y, z}}} * r)[0][0] << '\n';
    }
    return 0;
}