Cod sursa(job #3191498)

Utilizator G3K0Airinei Gabriel Vlad G3K0 Data 9 ianuarie 2024 20:18:49
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <bits/stdc++.h>

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

int A,B,C,X,Y,Z,n;
struct Mat
{
    int mat[3][3];
};
const int  mod=666013;
Mat S;
Mat prodmat (Mat A, Mat B)
{
    Mat C;
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
        {
            C.mat[i][j]=0;
            for(int k=0; k<3; k++)
                C.mat[i][j]=(  C.mat[i][j]+(  A.mat[i][k] * B.mat[k][j])%mod)%mod;
        }
    return C;
}
Mat putere (Mat a,int n)
{
    if(n==1)
        return a;
    if(n%2==1)
        return prodmat(a,putere(a,n-1));
    Mat p=putere(a,n/2);
    return prodmat(p,p);
}
int main()
{
    int t;
    f>>t;
    while(t--)
    {
        f>>X>>Y>>Z>>A>>B>>C>>n;
        S=
        {
            {

                {0,1,0},
                {0,0,1},
                {C,B,A}
            }
        };

        Mat rez=putere(S,n-2);


        int nr=((rez.mat[2][0]*X)%mod+(rez.mat[2][1]*Y)%mod+(rez.mat[2][2]*Z)%mod)%mod;
        g<<nr<<'\n';

    }

    return 0;
}