Cod sursa(job #2665685)

Utilizator OffuruAndrei Rozmarin Offuru Data 31 octombrie 2020 11:08:37
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MOD=666013;
int x,y,z,A,B,C,n;

struct Mat{
    int mat[3][3]={0};
}M;

Mat inmultime(Mat a,Mat b)
{
    Mat rez;
    int i,j,x;
    for(i=0;i<3;i++) {
        for(j=0;j<3;j++) {
            rez.mat[i][j] = 0;
            for(x=0;x<3;x++) {
                rez.mat[i][j] += (1LL*a.mat[i][x]*b.mat[x][j])%MOD;
            }
        }
    }
    return rez;
}

Mat putere(Mat a,int e)
{
    Mat rez;
    for(int i=0;i<3;i++)
        rez.mat[i][i]=1;

    while(e)
    {
        if(e%2==1)
            rez=inmultime(rez,a);
        a=inmultime(a,a);
        e=e/2;
    }
    return rez;
}

void print(Mat a)
{
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
            cout<<a.mat[i][j]<<" ";
        cout<<"\n";
    }
}

void read()
{
    int t;
    fin>>t;

    while(t)
    {
    fin>>x>>y>>z>>A>>B>>C>>n;
    M.mat[0][2]=C;
    M.mat[1][0]=1;
    M.mat[1][2]=B;
    M.mat[2][1]=1;
    M.mat[2][2]=A;
    Mat X=putere(M,n-2);
    fout<<X.mat[0][2]*x+X.mat[1][2]*y+X.mat[2][2]*z<<"\n";
    t--;
    }
}

int main()
{
    read();
    return 0;
}