Pagini recente » Cod sursa (job #2489047) | Cod sursa (job #1812008) | Cod sursa (job #984036) | Cod sursa (job #1368483) | Cod sursa (job #2199101)
#include <cmath>
#include <cstdio>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("iepuri.in");
ofstream out("iepuri.out");
const int mod = 666013;
void multiply(long long a[3][3], long long b[3][3], long long multiply[3][3]) {
int sum;
long long aux[3][3];
for (int c = 0; c < 3; c++) {
for (int d = 0; d < 3; d++) {
sum = 0;
for (int k = 0; k < 3; k++) {
sum = (sum + (1LL * a[c][k] * b[k][d]) % mod) % mod;
}
aux[c][d] = sum;
}
}
for (int c = 0; c < 3; c++) {
for (int d = 0; d < 3; d++) {
multiply[c][d] = aux[c][d];
}
}
}
long long result[3][3];
void power(long long matrix[3][3], long exponent) {
if (exponent == 1) {
for (int c = 0; c < 3; c++) {
for (int d = 0; d < 3; d++) {
result[c][d] = matrix[c][d];
}
}
return;
}
power(matrix, exponent / 2);
multiply(result, result, result);
if (exponent % 2 == 1) {
multiply(result, matrix, result);
}
}
long long matrix[3][3];
int t, x, y, z, a, b, c;
long long n;
int main() {
in >> t;
for (int i = 0; i < t; i++) {
in >> x >> y >> z >> a >> b >> c >> n;
matrix[0][0] = a;
matrix[0][1] = b;
matrix[0][2] = c;
matrix[1][0] = 1;
matrix[2][1] = 1;
power(matrix, n - 2);
int ans = (1LL * result[0][0] * z + 1LL * result[0][1] * y + 1LL * result[0][2] * x) % mod;
out << ans << "\n";
}
return 0;
}