Cod sursa(job #2713965)

Utilizator mihnea.anghelMihnea Anghel mihnea.anghel Data 28 februarie 2021 23:23:56
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <fstream>
#define MOD 666013
#define f in
#define g out

using namespace std;
ifstream in ( "iepuri.in" );
ofstream out( "iepuri.out" );
long long mat[5][5], sol[5][5], aux[5][5];
long long t, n, x, y, z, a, b, c, i, j, sum, expo;

void copiaza ( long long a[5][5], long long b[5][5] ){
    for ( int i = 1; i <= 3; i++ )
        for ( int j = 1; j <= 3; j++ )
            a[i][j] = b[i][j];
}

void inmulteste ( long long a[5][5], long long b[5][5], long long c[5][5] ){
    for ( int i = 1; i <= 3; i++ )
        for ( int j = 1; j <= 3; j++ ){
            c[i][j] = 0;
            for ( int k = 1; k <= 3; k++ ){
                c[i][j] += (a[i][k] * b[k][j])%MOD;
                c[i][j] %= MOD;
            }
        }
}

int main() {
    for ( f>>t; t--; ){
        f>>x>>y>>z>>a>>b>>c>>n;
        for ( i = 1; i <= 3; i++ )
            for ( j = 1; j <= 3; j++ ){
                mat[i][j] = 0;
                if ( i == j )
                    sol[i][j] = 1;
                else sol[i][j] = 0;
            }
        mat[1][1] = a; mat[1][2] = b; mat[1][3] = c;
        mat[2][1] = mat[3][2] = 1;
        
        n -= 2;
        while ( n ){
            if ( n%2 ){
                inmulteste ( mat, sol, aux );
                copiaza ( sol, aux );
            }
            inmulteste ( mat, mat, aux );
            copiaza ( mat, aux );
            n /= 2;
        }
        g<<(sol[1][1]*z+sol[1][2]*y+sol[1][3]*x)%MOD<<"\n";
    }
    return 0;
}