Pagini recente » Cod sursa (job #2543706) | Cod sursa (job #1306111) | Cod sursa (job #771093) | Cod sursa (job #36375) | Cod sursa (job #1193184)
#include <fstream>
#include <cstring>
#define MOD 666013
#define LL long long
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
LL t,x,y,z,a,b,c,n,V[3][3],Rez[3][3],Aux[3][3];
inline void Multiply(LL x[3][3], LL y[3][3])
{
for(int i=0; i<=2; i++)
{
for(int j=0; j<=2; j++)
{
Aux[i][j] = 0;
for(int k=0; k<=2; k++)
{
Aux[i][j] = (x[i][k] * y[k][j] + Aux[i][j]) % MOD;
}
}
}
for(int i=0; i<=2; i++)
{
for(int j=0; j<=2; j++)
{
x[i][j] = Aux[i][j];
}
}
}
int main()
{
fin >> t;
for(int i=1; i<=t; i++)
{
fin >> x >> y >> z >> a >> b >> c >> n;
memset(V ,0, sizeof(V));
memset(Rez, 0, sizeof(Rez));
Rez[0][0] = Rez[1][1] = Rez[2][2] = 1;
V[0][1] = V[1][2] = 1;
V[2][0] = c; V[2][1] = b; V[2][2] = a;
n-=2;
for(; n; n/=2)
{
if(n & 1) Multiply(Rez, V);
Multiply(V, V);
}
fout << (Rez[2][0]*x + Rez[2][1]*y + Rez[2][2]*z) % MOD << '\n';
}
fout.close();
return 0;
}