Cod sursa(job #1883942)

Utilizator saba_alexSabadus Alex saba_alex Data 18 februarie 2017 12:30:53
Problema Iepuri Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int MOD = 666013;
int t, a, b, c, x, y, z, n;

struct matrix{

    long long m[3][3];
    void operator *= (const matrix &a){

        matrix c;
        for(int i = 0; i < 3; ++i)
            for(int j = 0; j < 3; ++j){
                c.m[i][j] = 0;
                for(int k = 0; k < 3; ++k)
                    c.m[i][j] += m[i][k] * a.m[k][j];
                c.m[i][j] %= MOD;
            }
        for(int i = 0; i < 3; ++i)
            for(int j = 0; j < 3; ++j)
                m[i][j] = c.m[i][j];
    }
};

int pwrlog(int n, matrix &t, matrix &r){

    for(int s = 1; s <= n; s <<= 1){
        if(n & s)
            t *= r;
        r *= r;
    }
}

int main()
{
    fin >> t;

    for(int i = 1; i <= t; ++i){
        fin >> x >> y >> z >> a >> b >> c >> n;

        matrix r = {0, 0, c, 1, 0, b, 0, 1, a};
        matrix t = {x, y, z, 0, 0, 0, 0, 0, 0};

        pwrlog(n, t, r);

        /**
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 3; ++j)
                cout << t.m[i][j] << ' ';
            cout << '\n';
        }
        cout << '\n';*/

        fout << t.m[0][0] << '\n';
    }

    return 0;
}