Pagini recente » Cod sursa (job #736481) | Cod sursa (job #658950) | Cod sursa (job #603056) | Cod sursa (job #2331697) | Cod sursa (job #2260013)
#include <fstream>
using namespace std;
ifstream cin ("iepuri.in");
ofstream cout ("iepuri.out");
const int MOD = 666013;
int t, x, y, z, a, b, c, n;
long long put[5][5], rez[5][5];
void multiply (long long a[][5], long long b[][5])
{
long long c[5][5];
for(int i = 1; i <= 3; ++i)
for(int j = 1; j <= 3; ++j)
c[i][j]=(a[i][1]*b[1][j]+a[i][2]*b[2][j]+a[i][3]*b[3][j])%MOD;
for(int i = 1; i <= 3; ++i)
for(int j = 1; j <= 3; ++j)
a[i][j] = c[i][j];
}
void print(long long a[][5])
{
for(int i = 1; i <= 3; ++i)
{
for(int j = 1; j <= 3; ++j)
cout << a[i][j] << ' ';
cout << '\n';
}
}
int main()
{
cin>>t;
while(t--)
{
cin>>x>>y>>z>>a>>b>>c>>n;
n-=2;
rez[1][1] = 1; rez[1][2] = 0; rez[1][3] = 0;
rez[2][1] = 0; rez[2][2] = 1; rez[2][3] = 0;
rez[3][1] = 0; rez[3][2] = 0; rez[3][3] = 1;
put[1][1] = a; put[1][2] = 1; put[1][3] = 0;
put[2][1] = b; put[2][2] = 0; put[2][3] = 1;
put[3][1] = c; put[3][2] = 0; put[3][3] = 0;
for(int mask = 1; mask <= n; mask<<=1)
{
if(n&mask)
multiply(rez, put);
multiply(put, put);
}
cout<<(rez[1][1]*z+rez[2][1]*y+rez[3][1]*x)%MOD<<'\n';
}
return 0;
}