Pagini recente » Cod sursa (job #2363364) | Cod sursa (job #90774) | Cod sursa (job #244440) | Cod sursa (job #2045807) | Cod sursa (job #1843314)
#include <cstdio>
#include <cstring>
#define MOD 666013
using namespace std;
struct mat3
{
int m[3][3];
mat3() {}
mat3(int diag)
{
m[0][0] = diag; m[0][1] = 0; m[0][2] = 0;
m[1][0] = 0; m[1][1] = diag; m[1][2] = 0;
m[2][0] = 0; m[2][1] = 0; m[2][2] = diag;
}
mat3 operator*(const mat3& a)
{
mat3 r;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
r.m[i][j] = 0;
for(int k = 0; k < 3; k++)
r.m[i][j] = (r.m[i][j] + 1LL * m[i][k] * a.m[k][j]) % MOD;
}
}
return r;
}
mat3& operator*=(const mat3& a)
{
mat3 r = *this * a;
memcpy(m, r.m, sizeof(m));
return *this;
}
};
mat3 powm(mat3 x, int b)
{
mat3 y(1);
while(b != 1)
{
if(b & 1)
{
b ^= 1;
y *= x;
}
else
{
b >>= 1;
x *= x;
}
}
return x * y;
}
int n, z0, z1, z2, a, b, c;
int main()
{
int t;
freopen("iepuri.in", "r", stdin);
freopen("iepuri.out", "w", stdout);
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d%d%d%d%d", &z0, &z1, &z2, &a, &b, &c, &n);
mat3 mat;
mat.m[0][0] = a; mat.m[0][1] = 1; mat.m[0][2] = 0;
mat.m[1][0] = b; mat.m[1][1] = 0; mat.m[1][2] = 1;
mat.m[2][0] = c; mat.m[2][1] = 0; mat.m[2][2] = 0;
mat3 znm2 = powm(mat, n - 2);
int zn = ((1LL * znm2.m[0][0] * z2) % MOD + (1LL * znm2.m[1][0] * z1) % MOD + (1LL * znm2.m[2][0] * z0) % MOD) % MOD;
printf("%d\n", zn);
}
return 0;
}