Pagini recente » Cod sursa (job #3254400) | Cod sursa (job #2539445) | Cod sursa (job #1361492) | Cod sursa (job #158485) | Cod sursa (job #3290371)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
#define MOD (666013LL)
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
vector<size_t> mul(vector<size_t>& a, vector<size_t>& b) {
vector<size_t> res(9);
for (size_t i = 0; i < 3; ++i) {
for (size_t j = 0; j < 3; ++j) {
for (size_t k = 0; k < 3; ++k) {
res[i * 3 + j] += a[i * 3 + k] * b[k * 3 + j] % MOD;
}
}
}
return res;
}
vector<size_t> exp(vector<size_t> a, size_t b) {
if (b == 1) {
return a;
}
if ((b & 1) == 0) {
auto x = exp(a, b >> 1);
return mul(x, x);
} else {
auto x = exp(a, b >> 1);
auto left = mul(a, x);
return mul(left, x);
}
}
void solve() {
size_t x, y, z, a, b, c, n;
fin >> x >> y >> z >> a >> b >> c >> n;
vector<size_t> mat = {0, 1, 0, 0, 0, 1, c, b, a};
mat = exp(mat, n - 2);
fout << (mat[6] * x + mat[7] * y + mat[8] * z) % MOD << '\n';
}
int main() {
size_t t;
fin >> t;
while (t) {
solve();
--t;
}
return 0;
}