Cod sursa(job #1276856)

Utilizator costty94Duica Costinel costty94 Data 26 noiembrie 2014 22:17:48
Problema Iepuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <iostream>
#include <fstream>
#define MOD 666013

using namespace std;

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

void copiaza(long long a[3][3], long long b[3][3])
{
	for (int i = 0; i <= 2; i++)
	{
		for (int j = 0; j <= 2; j++)
			a[i][j] = b[i][j];
	}
}

void inmultire(long long a[3][3], long long b[3][3], long long c[3][3])
{
	for (int i = 0; i <= 2; i++)
	{
		for (int j = 0; j <= 2; j++)
		{
			c[i][j] = 0;
			for (int k = 0; k <= 2; k++)
			{
				c[i][j] += a[i][k] * b[k][j];
				c[i][j] = c[i][j] % MOD;
			}
		}
	}
}

int main()
{
	int a, b, c, x, y, z, t, n, v, k;
	long long c1[3][3];
	f >> t;
	for (int i = 1; i <= t; i++)
	{
		f >> a >> b >> c >> x >> y >> z >> n;
		n = n - 2;
		long long r[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, {0, 0, 1} };
		long long a1[3][3] = { { x, y, z }, { 1, 0, 0 }, { 0, 1, 0 } };
		
		while (n != 0)
		{
			if (n % 2 == 1)
			{
				inmultire(a1, r, c1);
				copiaza(r, c1);
			}
			inmultire(a1, a1, c1);
			copiaza(a1, c1);
			n = n / 2;
		}
		g <<( c * r[0][0] + b * r[0][1] + a * r[0][2]) % MOD;
		g << endl;
		
	}
}