Pagini recente » Cod sursa (job #1671913) | Cod sursa (job #2211508) | Cod sursa (job #3266203) | Cod sursa (job #1113511) | Cod sursa (job #583435)
Cod sursa(job #583435)
#include <cstdio>
using namespace std;
#define r 666013
short x, y, z, a, b, c;
long n;
long m[4][4], M[4][4], MC[4][4];
void init(long x[][4])
{
x[1][2] = x[2][3] = 1;
x[3][1] = c; x[3][2] = b; x[3][3] = a;
for(short i=1; i<=3; i++)
for(short j=1; j<=3; j++)
MC[i][j] = 0;
}
void produs(long A[][4], long B[][4])
{
for(short k=1; k<=3; k++)
for(short i=1; i<=3; i++)
for(short j=1; j<=3; j++)
MC[k][i] += (A[k][j] * B[j][i])%r;
for(short i=1; i<=3; i++)
for(short j=1; j<=3; j++)
{
M[i][j] = MC[i][j];
MC[i][j] = 0;
}
/*
for(short i=1; i<=3; i++)
{
for(short j=1; j<=3; j++)
printf("%ld ", M[i][j]);
printf("\n");
}
printf("\n");
*/
}
void m_la_n()
{
while(n)
{
if(!n%2)
{
n /= 2;
produs(M, M);
}
n--;
produs(M, m);
}
}
void afisare()
{
long sol = ( (M[3][1]*x)%r + (M[3][2]*y)%r + (M[3][3]*z)%r )%r;
printf("%ld\n", sol);
}
void citire()
{
short T;
freopen("iepuri.in","r",stdin); scanf("%hd", &T);
for(; T; T--)
{
scanf("%hd %hd %hd %hd %hd %hd %ld", &x, &y, &z, &a, &b, &c, &n);
n = n-3;
init(m); init(M);
m_la_n();
afisare();
}
}
int main()
{
freopen("iepuri.out","w",stdout);
citire();
return 0;
}