Cod sursa(job #2303127)

Utilizator papinub2Papa Valentin papinub2 Data 15 decembrie 2018 17:46:53
Problema Iepuri Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define MOD 666013

using namespace std;

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

void Multiply (vector<vector<int> >&A, vector<vector<int> >&B)
{
    int row = A.size();
    int col = A[0].size();
    vector<vector<int> > C(row, vector<int>(col));

    for (int i = 0; i < row; i++)
        for (int j = 0; j < 3; j++)
            for (int w = 0; w < col; w++)
            C[i][j] = (1LL * C[i][j] + 1LL * A[i][w] * B[w][j]) % MOD;

    for (int i = 0; i < row; i++)
        for (int j = 0; j < col; j++)
            A[i][j] = C[i][j];
}

int main()
{
    int T;

    in.sync_with_stdio(false);
    in >> T;

    while (T--)
    {
        int x, y, z, a, b, c, n;
        in >> x >> y >> z >> a >> b >> c >> n;

        vector<vector<int> > Sol(1, vector<int>(3));
        vector<vector<int> > Mat(3, vector<int>(3));

        Sol[0][0] = x;
        Sol[0][1] = y;
        Sol[0][2] = z;

        Mat[0][2] = c;
        Mat[1][0] = 1;
        Mat[1][2] = b;
        Mat[2][1] = 1;
        Mat[2][2] = a;

        for (int i = 0; (1<<i) <= n; i++)
        {
            if ((1<<i)&n)
                Multiply(Sol, Mat);
            Multiply(Mat, Mat);
        }

        out << Sol[0][0] << '\n';
    }

    return 0;
}