Pagini recente » Cod sursa (job #1841480) | Cod sursa (job #25559) | Cod sursa (job #3173824) | Cod sursa (job #2689263) | Cod sursa (job #2047452)
#include <bits/stdc++.h>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
const int mod = 666013;
struct matrice {
int a, b, c, d, e, f, g, h, i;
matrice() { // 0 1 0
a = 0; // 0 0 1
b = 1; // 0 0 0
c = 0;
d = 0;
e = 0;
f = 1;
g = 0;
h = 0;
i = 0;
}
};
matrice M;
matrice produs(matrice A, matrice B)
{
matrice C;
C.a = ((1LL * A.a * B.a) % mod + (1LL * A.b * B.d) % mod + (1LL * A.c * B.g) % mod) % mod;
C.b = ((1LL * A.a * B.b) % mod + (1LL * A.b * B.e) % mod + (1LL * A.c * B.h) % mod) % mod;
C.c = ((1LL * A.a * B.c) % mod + (1LL * A.b * B.f) % mod + (1LL * A.c * B.i) % mod) % mod;
C.d = ((1LL * A.d * B.a) % mod + (1LL * A.e * B.d) % mod + (1LL * A.f * B.g) % mod) % mod;
C.e = ((1LL * A.d * B.b) % mod + (1LL * A.e * B.e) % mod + (1LL * A.f * B.h) % mod) % mod;
C.f = ((1LL * A.d * B.c) % mod + (1LL * A.e * B.f) % mod + (1LL * A.f * B.i) % mod) % mod;
C.g = ((1LL * A.g * B.a) % mod + (1LL * A.h * B.d) % mod + (1LL * A.i * B.g) % mod) % mod;
C.h = ((1LL * A.g * B.b) % mod + (1LL * A.h * B.e) % mod + (1LL * A.i * B.h) % mod) % mod;
C.i = ((1LL * A.g * B.c) % mod + (1LL * A.h * B.f) % mod + (1LL * A.i * B.i) % mod) % mod;
return C;
}
matrice putere(matrice A, long long n)
{
if(n == 0)
return M;
if(n == 1)
return A;
if(n % 2 == 0) {
return putere(produs(A, A), n / 2);
}
else {
return produs(A, putere(produs(A, A), n / 2));
}
}
int main()
{
int T;
f >> T;
for(int i = 1; i <= T; ++i) {
int x, y, z, a, b ,c ,n;
f >> x >> y >> z >> a >> b >> c >> n;
M.g = c;
M.h = b;
M.i = a;
matrice sol = putere(M, n - 2);
long long ans = (1LL * sol.g * x + 1LL * sol.h * y + 1LL * sol.i * z) % mod;
g << ans << '\n';
}
return 0;
}