Pagini recente » Cod sursa (job #567174) | Cod sursa (job #407418) | Cod sursa (job #1518406) | Cod sursa (job #489671) | Cod sursa (job #2983535)
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666013;
int A[3][3];
int I[3][3];
int x, y, z, a, b, c, n;
void init()
{
A[0][2] = A[1][1] = A[2][1] = A[2][2] = 0;
A[0][1] = A[1][2] = 1;
A[0][0] = a;
A[1][0] = b;
A[2][0] = c;
//
for(int i = 0; i < 3; ++i)
{
for(int j = i + 1; j < 3; ++j)
I[i][j] = I[j][i] = 0;
I[i][i] = 1;
}
}
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] = (c[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
}
memcpy(a, c, sizeof(c));
}
void puteremat(int p)
{
while(p > 0)
if(p % 2 == 0)
{
multmat(A, A);
p /= 2;
}
else
{
multmat(I, A);
p--;
}
}
int main()
{
int k;
fin >> k;
while(k--)
{
fin >> x >> y >> z >> a >> b >> c >> n;
init();
puteremat(n - 2);
fout << (1LL * z * I[0][0] + 1LL * y * I[1][0] + 1LL * x * I[2][0]) % MOD << '\n';
}
fin.close();
fout.close();
return 0;
}