Pagini recente » Cod sursa (job #1967848) | Arhiva de probleme | Cod sursa (job #1043344) | Cod sursa (job #563963) | Cod sursa (job #1276844)
#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, i;
long long n, c1[3][3];
f >> t;
for (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] = { { a, b, c }, { 1, 0, 0 }, { 0, 1, 0 } };
while (n != 0)
{
if (n % 2 == 1)
{
inmultire(r, a1, c1);
copiaza(r, c1);
}
inmultire(a1, a1, c1);
copiaza(a1, c1);
n = n / 2;
}
g << a * r[0][0] + b * r[0][1] + c * r[0][2];
g << endl;
}
}