Cod sursa(job #2637646)

Utilizator OvidRata Ovidiu Ovid Data 23 iulie 2020 20:24:08
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.64 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
#define MOD (666013)

ifstream fin("iepuri.in"); ofstream fout("iepuri.out");
#define cin fin
#define cout fout

int t, n, x, y, z, a, b, c;
int** null=new int*[3];




int** multip(int **m1, int**m2){
int **m3=new int*[3];
m3[0]=new int[3]; m3[1]=new int[3]; m3[2]=new int[3];

m3[0][0]=( ((m1[0][0]*m2[0][0])%MOD) +((m1[0][1]*m2[1][0])%MOD)+((m1[0][2]*m2[2][0])%MOD) )%MOD;
m3[0][1]=( ((m1[0][0]*m2[0][1])%MOD) +((m1[0][1]*m2[1][1])%MOD)+((m1[0][2]*m2[2][1])%MOD) )%MOD;
m3[0][2]=( ((m1[0][0]*m2[0][2])%MOD) +((m1[0][1]*m2[1][2])%MOD)+((m1[0][2]*m2[2][2])%MOD) )%MOD;

m3[1][0]=(((m1[1][0]*m2[0][0])%MOD) +((m1[1][1]*m2[1][0])%MOD)+((m1[1][2]*m2[2][0])%MOD) )%MOD;
m3[1][1]=(((m1[1][0]*m2[0][1])%MOD) +((m1[1][1]*m2[1][1])%MOD)+((m1[1][2]*m2[2][1])%MOD) )%MOD;
m3[1][2]=(((m1[1][0]*m2[0][2])%MOD) +((m1[1][1]*m2[1][2])%MOD)+((m1[1][2]*m2[2][2])%MOD) )%MOD;

m3[2][0]=( ((m1[2][0]*m2[0][0])%MOD)+((m1[2][1]*m2[1][0])%MOD)+((m1[2][2]*m2[2][0])%MOD) )%MOD;
m3[2][1]=( ((m1[2][0]*m2[0][1])%MOD)+((m1[2][1]*m2[1][1])%MOD)+((m1[2][2]*m2[2][1])%MOD) )%MOD;
m3[2][2]=( ((m1[2][0]*m2[0][2])%MOD)+((m1[2][1]*m2[1][2])%MOD)+((m1[2][2]*m2[2][2])%MOD) )%MOD;
return m3;
}



int**mat_exp(int **mat, int e){
int **mat_sq=new int*[3];
mat_sq[0]=new int[3]; mat_sq[1]=new int[3]; mat_sq[2]=new int[3];
mat_sq=multip(mat, mat);

if(e==1){
    return mat;
}
if(e==0){
    return null;
}


return multip(  mat_exp(mat, e%2), mat_exp(mat_sq, e/2)    );



}







int32_t main(){
INIT
null[0]=new int[3]; null[1]=new int[3]; null[2]=new int[3];
null[0][0]=1; null[0][1]=0;null[0][2]=0;
null[1][0]=0; null[1][1]=1;null[1][2]=0;
null[2][0]=0; null[2][1]=0;null[2][2]=1;

cin>>t;
while(t--){
    cin>>x>>y>>z>>a>>b>>c>>n;
    int **m0; m0=new int*[3];
    m0[0]=new int[3]; m0[1]=new int[3]; m0[2]=new int[3];
    m0[0][0]=a; m0[1][0]=b; m0[2][0]=c;
    m0[0][1]=1; m0[1][1]=0; m0[2][1]=0;
    m0[0][2]=0; m0[1][2]=1; m0[2][2]=0;
    int**res; res=new int*[3];
    res[0]=new int[3]; res[1]=new int[3]; res[2]=new int[3];
    res[0][0]=z; res[0][1]=y; res[0][2]=x;
    res[1][0]=0; res[1][1]=0; res[1][2]=0;
    res[2][0]=0; res[2][1]=0; res[2][2]=0;
    res=multip(res, mat_exp(m0, n-2) );
    cout<<res[0][0]<<"\n";
    delete m0;
}




return 0;
}