Pagini recente » Cod sursa (job #885915) | Cod sursa (job #2556033) | Cod sursa (job #375614) | Cod sursa (job #3156281) | Cod sursa (job #2872812)
#include <bits/stdc++.h>
#define MOD 666013
using namespace std;
/*******************************/
// INPUT / OUTPUT
ifstream f("iepuri.in");
ofstream g("iepuri.out");
/*******************************/
/// GLOBAL DECLARATIONS
int T;
int X, Y, Z, A, B, C, N;
int mat1[5][5], mat2[5][5], res[5][5], temp[5][5];
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> T;
}
///-------------------------------------
void Reset(int mat[5][5])
{
for (int i = 1 ; i <= 3 ; ++ i)
for (int j = 1 ; j <= 3 ; ++ j)
mat[i][j] = 0;
}
///-------------------------------------
inline void Init()
{
Reset(temp);
Reset(mat1);
Reset(mat2);
Reset(res);
mat1[1][1] = X, mat1[1][2] = Y, mat1[1][3] = Z;
mat2[1][1] = 0, mat2[1][2] = 0, mat2[1][3] = C;
mat2[2][1] = 1, mat2[2][2] = 0, mat2[2][3] = B;
mat2[3][1] = 0, mat2[3][2] = 1, mat2[3][3] = A;
res[1][1] = 1, res[2][2] = 1, res[3][3] = 1;
}
///-------------------------------------
inline void Read()
{
f >> X >> Y >> Z >> A >> B >> C >> N;
}
///-------------------------------------
void Multiply(int a[5][5], int b[5][5], int c[5][5])
{
Reset(temp);
for (int i = 1 ; i <= 3 ; ++ i)
for (int j = 1 ; j <= 3 ; ++ j)
for (int k = 1 ; k <= 3 ; ++ k)
temp[i][j] += (a[i][k] * b[k][j]) % MOD;
for (int i = 1 ; i <= 3 ; ++ i)
for (int j = 1 ; j <= 3 ; ++ j)
c[i][j] = temp[i][j] % MOD;
}
///-------------------------------------
void Print(int mat[5][5])
{
for (int i = 1 ; i <= 3 ; ++ i)
{
for (int j = 1 ; j <= 3 ; ++ j)
{
g << mat[i][j] << " ";
}
g << "\n";
}
g << "/-------------------------------------\n";
}
///-------------------------------------
inline void LogPut(int put)
{
while (put)
{
if (put & 1) Multiply(res, mat2, res);
Multiply(mat2, mat2, mat2);
put >>= 1;
}
}
///-------------------------------------
inline void Solve()
{
LogPut(N - 2);
Multiply(mat1, res, mat1);
}
///-------------------------------------
inline void Output()
{
g << mat1[1][3] << "\n";
}
///-------------------------------------
inline void TestCase()
{
Read();
Init();
Solve();
Output();
}
///-------------------------------------
inline void Solution()
{
while (T --)
{
TestCase();
}
}
///-------------------------------------
int main()
{
ReadInput();
Solution();
return 0;
}