Pagini recente » Cod sursa (job #1366020) | Cod sursa (job #531126) | Cod sursa (job #32148) | Cod sursa (job #788638) | Cod sursa (job #2764436)
#include <fstream>
#include <iostream>
using namespace std;
int T;
const int MOD = 666013;
ifstream f;
ofstream g;
struct matrix {
int a[3][3];
matrix operator* (matrix b) {
matrix rez = {{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}};
int i, j, k;
for (i = 0; i < 3; i++)
for (k = 0; k < 3; k++)
for (j = 0; j < 3; j++)
rez.a[i][j] = (rez.a[i][j] + 1LL * a[i][k] * b.a[k][j]) % MOD;
return rez;
}
};
matrix exp(matrix a, int b) {
matrix P = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}};
while (b) {
if (b & 1)
P = P * a;
a = a * a;
b /= 2;
}
return P;
}
void solve() {
int x, y, z, A, B, C, n;
f >> x >> y >> z >> A >> B >> C >> n;
matrix m1 = {{{0, 1, 0}, {0, 0, 1}, {C, B, A}}};
m1 = exp(m1, n);
g << (1LL * x * m1.a[0][0] % MOD + 1LL * y * m1.a[0][1] % MOD + 1LL * z * m1.a[0][2] % MOD) % MOD << '\n';
}
void read() {
f.open("iepuri.in");
g.open("iepuri.out");
f >> T;
while (T--)
solve();
f.close();
g.close();
}
int main() {
read();
return 0;
}