Pagini recente » Cod sursa (job #992957) | Cod sursa (job #2718039) | Cod sursa (job #2324254) | Cod sursa (job #104648) | Cod sursa (job #2291073)
#include <fstream>
#include <cstring>
using namespace std;
const int MOD = 666013;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
int T, X, Y, Z, A, B, C, N;
void multmat(int a[][3], int b[][3])
{
int c[3][3];
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
{
c[i][j] = 0;
for(int k = 0; k < 3; k++)
c[i][j] += 1LL * a[i][k] * b[k][j] % MOD;
c[i][j] %= MOD;
}
memcpy(a, c, sizeof(c));
}
int puteremat(int p)
{
int M[3][3] = {{A, 1, 0}, {B, 0, 1}, {C, 0, 0}};
int I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while(p > 0)
{
if(p % 2 == 0)
{
multmat(M, M);
p /= 2;
}
else
{
multmat(I, M);
p--;
}
}
return (1LL * Z * I[0][0] + 1LL * Y * I[1][0] + 1LL * X * I[2][0]) % MOD;
}
int main()
{
f >> T;
while(T--)
{
f >> X >> Y >> Z >> A >> B >> C >> N;
g << puteremat(N - 2) << '\n';
}
return 0;
}