Cod sursa(job #599380)

Utilizator luckyme91wiz kid luckyme91 Data 28 iunie 2011 16:28:06
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <fstream>
#include <vector>


using namespace std;

typedef vector < vector <long long> > V;

V mult (V a, V b)
{
	V c(3, vector <long long> (3));
	int i;
	for (i = 0; i < 3; i++)
	{
		c[i][0] = a[i][0] * b[0][0] + a[i][1] * b[1][0] + a[i][2] * b[2][0];
		c[i][1] = a[i][0] * b[0][1] + a[i][1] * b[1][1] + a[i][2] * b[2][1];
		c[i][2] = a[i][0] * b[0][2] + a[i][1] * b[1][2] + a[i][2] * b[2][2];
	}
	return c;
}

	

V pwr (V a, int n)
{
	if (n == 1)
		return a;
	else
		if (n % 2 == 0)
			return mult (pwr (a,n/2), pwr (a, n/2));
		else
		{
			V temp;
			temp =  mult (pwr (a,n/2), pwr (a, n/2));
			return mult (temp, pwr(a, 1));
		}
}


int main () {

ifstream in ("iepuri.in");
ofstream out ("iepuri.out");

int n, a, b, c, x, y, z, day;
in >> n;
V m_n;
for (;n > 0; n--)
{
	in >> a >> b >> c;
	in >> x >> y >> z;
	in >> day;
	vector < vector <long long> > m(3, vector <long long> (3,0));
	m[2][0] = z;
	m[2][1] = y;
	m[2][2] = x;
	m[0][1] = 1;
	m[1][2] = 1;
	m_n = pwr (m, day);
long long p = m_n[0][0] * a + m_n[0][1] * b + m_n[0][2] *c;
out << p % 666013 << endl;

}
return 0;
}