Pagini recente » Istoria paginii runda/oni2012_ziua1/clasament | Cod sursa (job #1491847) | Cod sursa (job #469278) | Cod sursa (job #1121913) | Cod sursa (job #1197377)
#include <cstdio>
#define MOD 666013
using namespace std;
int X,Y,Z,A,B,C,N;
int aux;
class matrice{
public:
long long M[3][3];
matrice(){
M[0][0] = M[0][1] = M[0][2] = 0;
M[1][0] = M[1][1] = M[1][2] = 0;
M[2][0] = M[2][1] = M[2][2] = 0;
}
matrice operator*(matrice m1)
{
matrice m;
for(int i = 0; i <= 2; ++i)
for(int j = 0; j <= 2; ++j)
for(int line = 0; line <= 2; ++line)
m.M[i][j] = (m.M[i][j]%MOD + (M[line][j] * m1.M[i][line])%MOD)%MOD;
return m;
}
void init_one(){
M[0][0] = M[1][1] = M[2][2] = 1;
}
void init_ABC(int A,int B,int C)
{
M[0][1] = M[1][2] = 1;
M[2][0] = C;
M[2][1] = B;
M[2][2] = A;
}
};
matrice lg_put(matrice m,int b)
{
matrice x1,x2;
x1 = m;
x2.init_one();
if(b == 0)
return x2;
if(b == 1)
return x1;
while(b > 1)
{
if(b & 1)
{
x2 = (x1 * x2);
b ^=1;
}
else
{
x1 = (x1 * x1);
b >>=1;
}
}
return (x1 * x2);
}
int main()
{
freopen("iepuri.in","r",stdin);
freopen("iepuri.out","w",stdout);
int T;
scanf("%d",&T);
for(int i = 1; i <= T; ++i)
{
scanf("%d%d%d%d%d%d%d",&X,&Y,&Z,&A,&B,&C,&N);
matrice m;
m.init_ABC(A,B,C);
m = lg_put(m,N-2);
printf("%d\n",((m.M[2][0]*X)%MOD + (m.M[2][1]*Y)%MOD + (m.M[2][2]*Z)%MOD)%MOD );
}
return 0;
}