Pagini recente » Cod sursa (job #1222676) | Cod sursa (job #856403) | Cod sursa (job #1146613) | Cod sursa (job #3033300) | Cod sursa (job #2429776)
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666013;
const int DIM = 4;
int X, Y, Z, A, B, C, N;
struct matrix
{
int N, M;
long long a[DIM][DIM];
matrix()
{
N = M = 0;
memset(a, 0, sizeof(a));
}
matrix operator * (const matrix other)
{
matrix rez;
rez.N = N;
rez.M = other.M;
for(int i = 1; i <= N; i++)
for(int j = 1; j <= other.M; j++)
for(int c = 1; c <= M; c++)
rez.a[i][j] = rez.a[i][j] + a[i][c] * other.a[c][j];
for(int i = 1; i <= N; i++)
for(int j = 1; j <= M; j++)
rez.a[i][j] %= MOD;
return rez;
}
};
matrix RidPut(int exp)
{
matrix sol, aux;
sol.N = sol.M = 3;
sol.a[1][1] = sol.a[2][2] = sol.a[3][3] = 1;
aux.N = aux.M = 3;
aux.a[2][1] = aux.a[3][2] = 1;
aux.a[1][3] = C, aux.a[2][3] = B, aux.a[3][3] = A;
for(int i = 1; i <= exp; i <<= 1)
{
if(i & exp)
sol = sol * aux;
aux = aux * aux;
}
return sol;
}
int main()
{
int T;
fin >> T;
matrix m;
m.N = 1;
m.M = 3;
while(T--)
{
fin >> X >> Y >> Z >> A >> B >> C >> N;
if(N <= 3)
{
if(N == 1)
fout << X << '\n';
else if(N == 2)
fout << Y << '\n';
else
fout << Z << '\n';
continue;
}
m.a[1][1] = X, m.a[1][2] = Y, m.a[1][3] = Z;
matrix p = RidPut(N - 2);
m = m * p;
fout << m.a[1][3] << '\n';
}
fin.close();
fout.close();
return 0;
}