Cod sursa(job #2758207)

Utilizator Madalin_IonutFocsa Ionut-Madalin Madalin_Ionut Data 8 iunie 2021 21:47:03
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <bits/stdc++.h>
#define MOD 666013

using namespace std;

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

int n, x, y, z, a, b, c, k, F[3][3], g[3][3], p[3][3];

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

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

void LogP(int n)
{
	p[0][0] = p[1][1] = p[2][2] = 1;
	p[0][1] = p[0][2] = p[1][0] = p[1][2] = p[2][0] = p[2][1] = 0;
	while (n > 0)
	{
		if (n % 2 == 1)
		{
			Produs(p, F, g);
			Copie(p, g);
		}
		n /= 2;
		Produs(F, F, g);
		Copie(F, g);
	}
}

void Citire()
{
	int i, sol;
	fin >> n;
	for (i = 1; i <= n; i++)
	{
		fin >> x >> y >> z >> a >> b >> c >> k;
		F[1][0] = F[2][1] = 1;
		F[0][0] = F[0][1] = F[1][1] = F[2][0] = 0;
		F[0][2] = c;
		F[1][2] = b;
		F[2][2] = a;
		LogP(k - 2);
		sol = (1LL * x * p[0][2] + 1LL * y * p[1][2] + 1LL * z * p[2][2]) % MOD;
		fout << sol << "\n";
	}
}

int main()
{
	Citire();
}