Pagini recente » Clasament simulare-cartita-38 | Cod sursa (job #2618524) | Cod sursa (job #33117) | Cod sursa (job #99633) | Cod sursa (job #1017590)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
const int mod = 666013;
typedef int Matrix[4][4];
int T, N, A, B, C, X, Y, Z;
inline void mult( Matrix &A, Matrix B )
{
Matrix aux;
memset( aux, 0, sizeof ( aux ) );
for ( int i = 1; i <= 3; ++i )
for ( int j = 1; j <= 3; ++j )
for ( int k = 1; k <= 3; ++k )
aux[i][j] = ( aux[i][j] + A[i][k] * B[k][j] * 1LL ) % mod;
memcpy( A, aux, sizeof ( aux ) );
}
int power()
{
Matrix SOL, I;
memset ( SOL, 0, sizeof ( SOL ) );
memset ( I, 0, sizeof ( I ) );
SOL[1][2] = SOL[2][3] = 1;
SOL[3][1] = C; SOL[3][2] = B; SOL[3][3] = A;
I[1][1] = 1;
I[2][2] = 1;
I[3][3] = 1;
for ( int i = 0; ( 1 << i ) <= N; ++i )
{
if ( N & ( 1 << i ) )
{
mult( I, SOL );
}
mult( SOL, SOL );
}
return ( I[1][1] * X + I[1][2] * Y + I[1][3] * Z ) % mod;
}
int main()
{
ifstream f("iepuri.in");
ofstream g("iepuri.out");
for ( f >> T; T; T-- )
{
f >> X >> Y >> Z >> A >> B >> C >> N;
g << power() << "\n";
}
return 0;
}