Pagini recente » Cod sursa (job #1564124) | Cod sursa (job #1427865) | Cod sursa (job #1226723)
#include <fstream>
#define MOD 666013
using namespace std;
int T, X, Y, Z, A, B, C, N;
int Matrix[50][10][10];
int A1[10][10];
int B1[10][10];
void Initializare (int A, int B, int C)
{
Matrix[0][1][1] = A;
Matrix[0][1][2] = B;
Matrix[0][1][3] = C;
Matrix[0][2][1] = 1;
Matrix[0][2][2] = 0;
Matrix[0][2][3] = 0;
Matrix[0][3][1] = 0;
Matrix[0][3][2] = 1;
Matrix[0][3][3] = 0;
for (int k = 1; k <= 31; k++)
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
{
Matrix[k][i][j] = 0;
for (int l = 1; l <= 3; l++)
Matrix[k][i][j] = (1LL * Matrix[k][i][j] + 1LL * Matrix[k - 1][i][l] * Matrix[k - 1][l][j]) % MOD;
}
A1[1][1] = 1;
A1[1][2] = 0;
A1[1][3] = 0;
A1[2][1] = 0;
A1[2][2] = 1;
A1[2][3] = 0;
A1[3][1] = 0;
A1[3][2] = 0;
A1[3][3] = 1;
}
int main ()
{
ifstream fin ("iepuri.in");
ofstream fout ("iepuri.out");
fin >> T;
for (; T; T--)
{
fin >> X >> Y >> Z >> A >> B >> C >> N;
Initializare (A, B, C);
N -= 2;
for (int pi = 30; pi >= 0; pi--)
if ((1 << pi) <= N)
{
N -= 1 << pi;
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
{
B1[i][j] = 0;
for (int k = 1; k <= 3; k++)
B1[i][j] = (1LL * B1[i][j] + 1LL * A1[i][k] * Matrix[pi][k][j]) % MOD;
}
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
A1[i][j] = B1[i][j];
}
fout << (A1[1][1] * Z + A1[1][2] * Y + A1[1][3] * X) % MOD << "\n";
}
fin.close ();
fout.close ();
return 0;
}