Cod sursa(job #3367440)

Utilizator Octavian09Dore Octaviam Octavian09 Data 7 octombrie 2026 19:59:01
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>

using namespace std;
const int MOD = 666013;

int X, Y, Z, A, B, C;

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

void mul(int A[][3], int B[][3]){
    long long c[3][3];
    int i, j, k;
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++){
            c[i][j] = 0;
            for(k = 0; k < 3; k++)
                c[i][j] += 1ll * A[i][k] * B[k][j];
        }
    //
    for(i = 0; i < 3;i++)
        for(j = 0; j < 3; j++)
            A[i][j] = c[i][j] % MOD;
}

int putere(int n){
    int M[3][3]={
        {0, 0, C},
        {1, 0, B},
        {0, 1, A},
    };
    int V[3][3]={
        {X, Y, Z},
        {0, 0, 0},
        {0, 0, 0},
    };
    //
    while(n > 0){
        if(n & 1)
            mul(V,M);
        mul(M,M);
        n >>= 1;
    }
    return V[0][2];
}

int main()
{
    int T, N;
    f >> T;
    while(T--){
        f >> X >> Y >> Z
          >> A >> B >> C
          >> N;
        g << putere(N - 2) << '\n';
    }
    return 0;
}