Pagini recente » Cod sursa (job #464822) | Cod sursa (job #291476) | Borderou de evaluare (job #1517319) | Cod sursa (job #1670360) | Cod sursa (job #3351292)
#include <fstream>
const int MOD=666013;
using namespace std;
ifstream in("iepuri.in");
ofstream out("iepuri.out");
int t,x,y,z,a,b,c,n;
int i,j,k;
int rez[4][4];
int unitara[4][4]={{0,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}};
int imat[4][4];
int sir[4][2];
void copymat(int dest[4][4], int source[4][4])
{
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
dest[i][j]=source[i][j];
}
void my_pow(int baza[4][4], int exp)
{
int aux[4][4];
while(exp!=0)
{
if(exp%2==0)
{
exp/=2;
///rid la patrat baza in aux si bag aux in baza --> baza^2
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
int s=0;
for(k=1;k<=3;k++)
s+=baza[i][k]*1LL*baza[k][j]%MOD;
aux[i][j]=s;
}
copymat(baza,aux);
}
else
{
exp--;
///bag aux*baza in rez
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
int s=0;
for(k=1;k<=3;k++)
s+=baza[i][k]*1LL*rez[k][j]%MOD;
aux[i][j]=s;
}
copymat(rez,aux);
}
}
}
int main()
{
in>>t;
while(t--)
{
in>>x>>y>>z>>a>>b>>c>>n;
imat[1][1]=0;
imat[1][2]=1;
imat[1][3]=0;
imat[2][1]=0;
imat[2][2]=0;
imat[2][3]=1;
imat[3][1]=c;
imat[3][2]=b;
imat[3][3]=a;
sir[1][1]=x;
sir[2][1]=y;
sir[3][1]=z;
copymat(rez,unitara);
my_pow(imat,n-2);
///sir * rez
int ans=(sir[1][1]*1LL*rez[3][1]%MOD + sir[2][1]*1LL*rez[3][2]%MOD + sir[3][1]*1LL*rez[3][3]%MOD)%MOD;
out<<ans<<'\n';
}
return 0;
}