Pagini recente » Cod sursa (job #1201403) | Cod sursa (job #2197318) | Cod sursa (job #405881) | Cod sursa (job #245505) | Cod sursa (job #2485508)
#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;
int x, y, z, a, b, c, n;
cin >> 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);
mat.afisare(); cout << endl;
A.afisare(); cout << endl;
cout << A.mat[1][0] * z +
A.mat[1][1] * y +
A.mat[1][2] * x; 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();
}