Pagini recente » Cod sursa (job #2647166) | Cod sursa (job #2951128) | Cod sursa (job #29807) | Cod sursa (job #1623499) | Cod sursa (job #805821)
Cod sursa(job #805821)
#include <iostream>
#include <fstream>
#include <cstdio>
#define MOD 666013
using namespace std;
int a[4][4],b[4][4],m[4];
int x,y,z,f,g,h,n,p;
void inmultire(int a[4][4],int b[4][4])
{
int i,j,k;
long long c[4][4];
for(i=0;i<=3;i++)
for(j=0;j<=3;j++)
c[i][j]=0;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
a[i][j]=c[i][j];
}
void putere(int &n)
{
while(n)
{
if(n%2==1)
inmultire(b,a);
n=n/2;
inmultire(a,a);
}
}
void aloc(int f,int g,int h,int x,int y,int z)
{
a[1][1]=0; a[1][2]=1; a[1][3]=0; a[2][1]=0; a[2][2]=0; a[2][3]=1; a[3][1]=h; a[3][2]=g; a[3][3]=f;
b[1][1]=0; b[1][2]=1; b[1][3]=0; b[2][1]=0; b[2][2]=0; b[2][3]=1; b[3][1]=h; b[3][2]=g; b[3][3]=f;
m[1]=x; m[2]=y; m[3]=z;
}
int main()
{
freopen("iepuri.in","r",stdin);
freopen("iepuri.out","w",stdout);
scanf("%d",&p);
while(p)
{ x=0;y=0;z=0;f=0;g=0;h=0;n=0;
scanf("%d %d %d %d %d %d %d",&x,&y,&z,&f,&g,&h,&n);
aloc(f,g,h,x,y,z);
n=n-3;
putere(n);
int q=b[3][1]*m[1]+b[3][2]*m[2]+b[3][3]*m[3];
q=q%MOD;
cout<<q<<"\n";
p--;
}
fclose(stdin);
fclose(stdout);
return 0;
}