Pagini recente » Cod sursa (job #166754) | Cod sursa (job #846799) | Cod sursa (job #1535135) | Cod sursa (job #166752) | Cod sursa (job #631452)
Cod sursa(job #631452)
#include <fstream>
#include <cstring>
using namespace std;
#define MOD 666013
void matrix_mult(int (*A)[3], int (*B)[3])
{
int i, j, k;
int aux[3][3];
memset(aux, 0, sizeof(aux));
for (i=0; i<3; ++i)
for (j=0; j<3; ++j)
for (k=0; k<3; ++k)
aux[i][j] += (1ll*A[i][k]*B[k][j])%MOD;
memcpy(A, aux, sizeof(aux));
}
int main()
{
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
int t;
int x, y, z, a, b, c, n;
fin >> t;
while (t--) {
fin >> x >> y >> z >> a >> b >> c >> n;
n -= 2;
int T[3][3] = {{0, 1, 0}, {0, 0, 1}, {c, b, a}};
int res[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (n) {
if (n%2)
matrix_mult(res, T);
matrix_mult(T, T);
n /= 2;
}
int result = (1ll*res[2][0]*x%MOD + 1ll*res[2][1]*y%MOD + 1ll*res[2][2]*z%MOD)%MOD;
fout << result << "\n";
}
return 0;
}