Cod sursa(job #2485510)

Utilizator LaurconsPricop Laurentiu Laurcons Data 1 noiembrie 2019 18:17:53
Problema Iepuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.96 kb
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
using namespace std;

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

class matrice {
public:
    int mat[3][3];

    matrice operator*(const matrice m) {
        matrice ret;
        for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) {
            ret.mat[i][j] = 0;
            for (int k = 0; k < 3; k++)
                ret.mat[i][j] += m.mat[i][k] * mat[k][j];
        }
        return ret;
    }

    matrice operator*(const int scalar) {
        matrice ret;
        for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) {
            ret.mat[i][j] = mat[i][j] * scalar;
        }
        return ret;
    }

    void afisare() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                cout << mat[i][j] << ' ';
            }
            cout << endl;
        }
    }

    void i() {
        for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) {
            if (i == j)
                mat[i][j] = 1;
            else mat[i][j] = 0;
        }
    }
} i3;

const int MOD = 1999999973;

matrice put_log(matrice n, int p) {
    matrice r = i3;
    while (p > 0) {
        if (p & 1) {
            r = n * r;
        }
        n = n * n;
        p>>=1;
    }
    return r;
}

int set_date() {
    int x, y, z, a, b, c, n;
    fin >> x >> y >> z >> a >> b >> c >> n;
    i3.i();
    matrice mat;
    mat.mat[0][0] = a;
    mat.mat[0][1] = b;
    mat.mat[0][2] = c;
    mat.mat[1][0] = 1;
    mat.mat[1][1] = 0;
    mat.mat[1][2] = 0;
    mat.mat[2][0] = 0;
    mat.mat[2][1] = 1;
    mat.mat[2][2] = 0;
    matrice A = put_log(mat, n - 1);
    fout << A.mat[1][0] * z +
            A.mat[1][1] * y +
            A.mat[1][2] * x << endl;
}

int main() {
    int n;
    fin >> n;
    for (int i = 0; i < n; i++)
        set_date();
}