Cod sursa(job #3274360)

Utilizator alecu2008Alecu Alexandru alecu2008 Data 6 februarie 2025 15:34:34
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

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


const int mod=666013;

int t,A,b,c,x,y,z;
long long int n;
int a[3][3]={},ans[3][3]={};
void init(int x,int y,int z,int A,int b,int c){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            a[i][j]=0;
        }
    }
    ans[0][0]=x;
    ans[0][1]=y;
    ans[0][2]=z;
    a[1][0]=1;
    a[2][1]=1;
    a[0][2]=c;
    a[1][2]=b;
    a[2][2]=A;
}



void multi(int a[3][3],int b[3][3]){
    int c[3][3]={};

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                c[i][j]=(c[i][j]+(1LL*a[i][k]*b[k][j])%mod)%mod;
            }
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            a[i][j]=c[i][j];
        }
    }

}

void expo(long long int pow){
    while(pow>0){
        if(pow%2){
            multi(ans,a);
        }
        multi(a,a);
        pow=pow/2;
    }
}




int main()
{
    fin>>t;
    for(int i=0;i<t;i++){
        fin>>x>>y>>z>>A>>b>>c>>n;
        init(x,y,z,A,b,c);
        expo(n-2);
        fout<<ans[0][2]<<'\n';
    }
}