Pagini recente » Cod sursa (job #1660033) | Cod sursa (job #1069374) | Cod sursa (job #1201932) | Cod sursa (job #1299) | Cod sursa (job #2679958)
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("iepuri.in");
ofstream out("iepuri.out");
const int mod = 666013;
long long i[3][3];
long long m[3][3];
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)); ///copiem pe c in a
}
void puteremat(int m[][3], int p)
{
while(p > 0)
if(p % 2 == 0)
{
multmat(m, m);
p /= 2;
}
else
{
multmat(i, m);
p--;
}
}
int main()
{
long long t, x, y, z, a, b, c, n;
in >> t;
while(t--)
{
in >> x >> y >> z >> a >> b >> c >> n;
int m[3][3] =
{
{0, 0, c},
{1, 0, b},
{0, 1, a}
};
memset(i, 0, sizeof(i));
i[0][0] = 1;
i[1][1] = 1;
i[2][2] = 1;
puteremat(m, n - 2);
out << (x * i[0][2] + y * i[1][2] + z * i[2][2]) % mod << '\n';
}
return 0;
}