Pagini recente » Cod sursa (job #3260984) | Cod sursa (job #3319622) | Cod sursa (job #3260987) | Cod sursa (job #2214980) | Cod sursa (job #3319640)
#include <bits/stdc++.h>
using namespace std;
#define MOD 666013
ifstream fin("patratele.in");
ofstream fout("patratele.out");
long long i, j, y, ib[5][5], t, a, b, c, x, z, n, ras[5][5];
void inm(long long a[][5], long long b[][5])
{
int i, j, y;
int c[5][5] = {0};
for (i = 1; i <= 3; i++)
for (j = 1; j <= 3; j++)
for (y = 1; y <= 3; y++)
{
c[i][j] += (a[i][y] * b[y][j]) % MOD;
c[i][j] %= MOD;
}
for (i = 1; i <= 3; i++)
for (j = 1; j <= 3; j++)
a[i][j] = c[i][j];
}
void rid(long long x[][5], int put)
{
memset(ras, 0, sizeof(ras));
ras[1][1] = ras[2][2] = ras[3][3] = 1;
while (put)
{
if (put % 2 == 1)
inm(ras, x);
inm(x, x);
put /= 2;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fin >> t;
while (t--)
{
fin >> x >> y >> z >> a >> b >> c >> n;
memset(ib,0,sizeof(ib));
ib[1][2] = 1;
ib[2][3] = 1;
ib[3][1] = a;
ib[3][2] = b;
ib[3][3] = c;
rid(ib, n);
fout << (ras[1][1] * x % MOD + ras[1][2] * y % MOD + ras[1][3] * z % MOD) % MOD;
}
return 0;
}