Mai intai trebuie sa te autentifici.

Cod sursa(job #806264)

Utilizator SebiSebiPirtoaca George Sebastian SebiSebi Data 2 noiembrie 2012 15:09:16
Problema Iepuri Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include<iostream>
#include<fstream>
using namespace std;

#define DIM 3
#define MOD 666013

int z[4][4],sol[4][4],a,b,c;

void mult(int x[][4], int y[][4], int n, int m)
{
	int z[4][4],i,j,k,s;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++) {
			s=0;
			for(k=1;k<=m;k++)
				s=(s+(1LL*x[i][k]*y[k][j])%MOD)%MOD;
			z[i][j]=s;
		}
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			x[i][j]=z[i][j];
}

void putere(int n)
{
	int i,j,x[4][4];
	for(i=1;i<=3;i++)
		for(j=1;j<=3;j++) {
			sol[i][j]=0;
			x[i][j]=0;
		}
	x[2][1]=1;
	x[3][2]=1;
	x[1][3]=c;
	x[2][3]=b;
	x[3][3]=a;
	sol[1][1]=1;
	sol[2][2]=1;
	sol[3][3]=1;
    for(i=0;(1<<i)<=n;i++) {
        if(((1<<i)&n)>0)
			mult(sol,x,3,3);
		mult(x,x,3,3);
	}
}

int main ()
{
	int i,t,x,y,z,n,aux;
	ifstream f("iepuri.in");
	ofstream g("iepuri.out");
	f>>t;
	for(i=1;i<=t;i++) {
		f>>x>>y>>z>>a>>b>>c>>n;
		aux=x;
		x=y;
		y=z;
		z=a*y+b*x+c*aux;
		putere(n-1);
		g<<((1LL*x*sol[1][1])%MOD+(1LL*y*sol[2][1])%MOD+(1LL*z*sol[3][1])%MOD)%MOD<<'\n';
	}
	f.close();
	g.close();
	return 0;
}