Pagini recente » Cod sursa (job #2592188) | Cod sursa (job #3280996) | Cod sursa (job #1945505) | Cod sursa (job #2613785) | Cod sursa (job #599400)
Cod sursa(job #599400)
#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,0));
int i, j, k;
/*
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];
}*/
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
for (k = 0; k < 3; k++)
c[i][j] = (c[i][j] + a[i][k] *b[k][j]) % 666013;
return c;
}
V pwr (V a, int n)
{
if (n == 1)
return a;
else
{
V temp = pwr (a, n/2);
if (n % 2 == 0)
return mult (temp, temp);
else
{
V temp1 = mult (temp, temp);
return mult (temp1, pwr(a, 1));
}
}
}
int main () {
ifstream in ("iepuri.in");
ofstream out ("iepuri.out");
int s = 666013;
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 % s + m_n[0][1] * b %s+ m_n[0][2] *c %s);
out << p % 666013 << endl;
}
return 0;
}