Cod sursa(job #2978160)

Utilizator oana75Ioana Prunaru oana75 Data 13 februarie 2023 10:43:36
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <iostream>
#include <fstream>

using namespace std;
const int MOD = 666013;

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

int a, b, c, x, y, z, nrt, zi;
int A[4][4], B[4][4];

void inmultire(int A[][4], int B[][4])
{
    long long C[4][4];
    int i, j, k;
    for(i = 1; i <= 3; i++)
        for(j = 1; j <= 3; j++)
    {
        C[i][j] = 0;
        for(k = 1; k <= 3; k++)
            C[i][j] += 1LL * A[i][k] * B[k][j];
    }
    for(i = 1; i <= 3; i++)
        for(j = 1; j <= 3; j++)
            A[i][j] = C[i][j] % MOD;
}

void putere(int n)
{
    while(n > 0)
    {
        if(n % 2 != 0)
            inmultire(B, A);
        inmultire(A, A);
        n /= 2;
    }
}

void initializare()
{
    A[1][1] = 0; A[1][2] = 0; A[1][3] = c;
    A[2][1] = 1; A[2][2] = 0; A[2][3] = b;
    A[3][1] = 0; A[3][2] = 1; A[3][3] = a;
}

int main()
{
    in >> nrt;
    for(int t = 1; t <= nrt; t++)
    {
        in >> x >> y >> z >> a >> b >> c >> zi;
        B[1][1] = 1;
        B[2][2] = 1;
        B[3][3] = 1;
        B[1][2] = B[1][3] = 0;
        B[2][1] = B[2][3] = 0;
        B[3][1] = B[3][2] = 0;
        initializare();
        putere(zi - 2);
        out << (1LL * x * B[1][3] + 1LL * y * B[2][3] + 1LL * z * B[3][3]) % MOD << '\n';
    }
    in.close();
    out.close();
    return 0;
}