Cod sursa(job #2711004)

Utilizator As932Stanciu Andreea As932 Data 23 februarie 2021 16:01:44
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>
#include <cstring>
#define ll long long

using namespace std;

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

const int mod = 666013;

int x, y, z, a, b, c, sol[3][3], mt[3][3], an[3][3];
ll n;

void mult(int a[][3], int b[][3]){
    int s[3][3];
    memset(s, 0, sizeof(s));

    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                s[i][j] = (s[i][j] + 1LL * a[i][k] * b[k][j]) % mod;

    memcpy(a, s, sizeof(s));
}

void pw(ll k){
    while(k){
        if(k & 1)
            mult(sol, mt);
        k >>= 1;
        mult(mt, mt);
    }
}

void solve(){
    cin >> x >> y >> z >> a >> b >> c >> n;

    memset(sol, 0, sizeof(sol));
    memset(mt, 0, sizeof(mt));

    mt[0][0] = mt[0][1] = 0, mt[0][2] = c;
    mt[1][0] = 1, mt[1][1] = 0, mt[1][2] = b;
    mt[2][0] = 0, mt[2][1] = 1, mt[2][2] = a;

    an[0][0] = x, an[0][1] = y, an[0][2] = z;
    sol[0][0] = sol[1][1] = sol[2][2] = 1;

    pw(n);
    mult(an, sol);

    cout << an[0][0] << "\n";
}

int main()
{
    int t;
    cin >> t;

    while(t--)
        solve();

    return 0;
}