Pagini recente » Cod sursa (job #2078626) | Cod sursa (job #1840379) | Cod sursa (job #2692568) | Cod sursa (job #532561) | Cod sursa (job #936839)
Cod sursa(job #936839)
#include <fstream>
#include <cstring>
#define LL long long
#define MOD 666013
using namespace std;
const char iname[] = "iepuri.in";
const char oname[] = "iepuri.out";
ifstream fin(iname);
ofstream fout(oname);
int X, Y, Z, L, H, S, N, Q;
LL Ans;
LL ANS[4][4], I[4][4], AUX[4][4], O[4][4];
void mul(LL A[4][4], LL B[4][4])
{
int i, j, n;
LL ad;
for (i = 1; i <= 3; ++i)
for (j = 1; j <= 3; ++j) O[i][j] = B[i][j];
for (i = 1; i <= 3; ++i)
for (j = 1; j <= 3; ++j) AUX[i][j] = A[i][j];
for (i = 1; i <= 3; ++i)
{
for (j = 1; j <= 3; ++j)
{
ad = 0;
for (n = 1; n <= 3; ++n)
ad += 1LL * AUX[i][n] * O[n][j];
A[i][j] = ad % MOD;
}
}
}
int main()
{
fin >> Q;
while (Q--)
{
fin >> X >> Y >> Z >> L >> H >> S >> N;
memset (ANS, 0, sizeof(ANS));
memset (I, 0, sizeof(I)); Ans = 0;
ANS[1][1] = ANS[2][2] = ANS[3][3] = 1; Ans = 0;
I[1][2] = I[2][3] = 1;
I[3][1] = S; I[3][2] = H; I[3][3] = L;
N -= 2;
for (; N > 0; N /= 2)
{
if (N % 2 == 1) mul(ANS, I);
mul(I, I);
}
Ans = 1LL * (ANS[3][1] * X) % MOD + 1LL * (ANS[3][2] * Y) % MOD + 1LL * (ANS[3][3] * Z) % MOD;
fout << Ans % MOD << '\n';
}
return 0;
}