Pagini recente » Cod sursa (job #1498781) | Cod sursa (job #1129934) | Cod sursa (job #648693) | Cod sursa (job #3269632) | Cod sursa (job #2856696)
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <cstring>
#include <climits>
#include <iomanip>
#include <stack>
#include <cstdio>
#define MOD 666013
using namespace std;
int n;
int x, y, z, a, b, c, p;
long long int matriceInd[4][4];//matricea cu care fac inmultirile
long long int matriceInmult[4][4];//matricea const la puterea n-1
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
void inmultireMatrici(long long int a[][4], long long int b[][4], long long int rez[][4])
{
//initializarea
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
rez[i][j] = 0;
}
}
for (int lin = 1; lin <= 3; lin++)
{
//linia din a
//inmultesc cu coloanele din b
for (int col = 1; col <= 3; col++)
{
for (int k = 1; k <= 3; k++)
{
long long int prod = 1LL * a[lin][k] * b[k][col];
rez[lin][col] = 1LL*(rez[lin][col] + prod) % MOD;
}
}
}
}
void putere(int k)
{
matriceInd[1][1] = 0;
matriceInd[1][2] = 1;
matriceInd[1][3] = 0;
matriceInd[2][1] = 0;
matriceInd[2][2] = 0;
matriceInd[2][3] = 1;
matriceInd[3][1] = c;
matriceInd[3][2] = b;
matriceInd[3][3] = a;
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
matriceInmult[i][j] = 0;
}
}
matriceInmult[1][1] = 1;
matriceInmult[2][2] = 1;
matriceInmult[3][3] = 1;
long long int aux[4][4];
while (k > 0)
{
if (k % 2 == 1)
{
inmultireMatrici(matriceInmult, matriceInd, aux);
memcpy(matriceInmult, aux, sizeof(aux));
}
inmultireMatrici(matriceInd, matriceInd, aux);
memcpy(matriceInd, aux, sizeof(aux));
k = k / 2;
}
}
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
{
fin >> x >> y >> z >> a >> b >> c >> p;
putere(p);
long long int rez = (matriceInmult[1][1]*x) %MOD;
rez = (rez + matriceInmult[1][2] * y) % MOD;
rez = (rez + matriceInmult[1][3] * z) % MOD;
fout << rez % MOD<<"\n";
}
return 0;
}