Cod sursa(job #2646969)

Utilizator DenisONIcBanu Denis Andrei DenisONIc Data 2 septembrie 2020 15:54:18
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <bits/stdc++.h>
using namespace std;

#define MOD 666013

vector<int> mat;
int t;

vector<int> mult(vector<int> A, vector<int> B){
    vector<int> ans(9);

    for (int i=0;i<3;i++)
    for (int j=0;j<3;j++){
        for (int k=0;k<3;k++){
            ans[i * 3 + j] = (ans[i*3 + j] + 1LL * A[i * 3 + k] * B[k * 3 + j]) % MOD;
        }
    }

    return ans;
}

vector<int> _pow(vector<int> A, int b){
    if (b==1) return A;
    if (b%2 == 0) return _pow(mult(A,A), b / 2);
    return mult(_pow(mult(A,A), b / 2), A);
}

int main()
{
    freopen("iepuri.in","r",stdin);
    freopen("iepuri.out","w",stdout);

    cin >> t;
    while (t--){
        int x,y,z,a,b,c,n;
        cin >> x >> y >> z >> a >> b >> c >> n;
        vector<int> A(9, 0);
        A[0] = a; A[1] = b; A[2] = c;
        A[3] = 1;
        A[7] = 1;

        A = _pow(A, n-2);
        cout << (1LL * A[0] * z + 1LL * A[1] * y + 1LL * A[2] * x) % MOD << '\n';
    }

    return 0;
}