# Cod sursa(job #2758605)

Utilizator Data 11 iunie 2021 16:06:16 Iepuri 100 cpp-64 done Arhiva de probleme 1.36 kb
``````#include <bits/stdc++.h>
#define MOD 666013
using namespace std;

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

int a[3][3], b[3][3], p[3][3];
int T, sol;
int n;

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)
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
p[i][j] = 0;
p[0][0] = p[1][1] = p[2][2] = 1;
while (n > 0)
{
if (n % 2 == 1)
{
Produs(p, a, b);
Copie(p, b);
}
n /= 2;
Produs(a, a, b);
Copie(a, b);
}
}

int main()
{
int X, Y, Z, A, B, C;
fin >> T;
while (T > 0)
{
fin >> X >> Y >> Z >> A >> B >> C >> n;
sol = 0;
a[0][0] = a[0][1] = a[1][1] = a[2][0] = 0;
a[1][0] = a[2][1] = 1;
a[0][2] = C; a[1][2] = B; a[2][2] = A;
LogP(n - 2);
sol = (1LL * p[0][2] * X + 1LL * p[1][2] * Y + 1LL * p[2][2] * Z) % MOD;
fout << sol << "\n";
T--;
}
return 0;
}
``````