Cod sursa(job #805811)

Utilizator SovStoStoicescu Mihail Cristian SovSto Data 1 noiembrie 2012 10:45:34
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#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)
	{	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];
		cout<<q<<"\n";p--;
}
	return 0;
}