Pagini recente » Cod sursa (job #192739) | Cod sursa (job #1419355) | Cod sursa (job #956451) | Cod sursa (job #1863467) | Cod sursa (job #2854594)
#include <bits/stdc++.h>
#define MOD 666013
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
int t, x, y, z, a, b, c, n;
void inmultireMat(int a[3][3], int b[3][3]) {
int rez[3][3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
rez[i][j] = (1LL * a[i][0] * b[0][j] + 1LL * a[i][1] * b[1][j] + 1LL * a[i][2] * b[2][j]) % MOD;
}
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
a[i][j] = rez[i][j];
}
}
}
int main() {
fin >> t;
while(t > 0) {
fin >> x >> y >> z >> a >> b >> c >> n;
int sol[3][3] = {
{0, 1, 0},
{0, 0, 1},
{c, b, a}
};
int aux[3][3] = {
{0, 1, 0},
{0, 0, 1},
{c, b, a}
};
n--;
while(n > 0) {
if(n % 2 != 0) {
inmultireMat(sol, aux);
}
inmultireMat(aux, aux);
n /= 2;
}
int ans = (1LL * sol[0][0] * x + 1LL * sol[0][1] * y + 1LL * sol[0][2] * z) % MOD;
fout << ans << "\n";
t--;
}
fin.close();
return 0;
}