Pagini recente » Cod sursa (job #1821597) | Cod sursa (job #2472330) | Cod sursa (job #645828) | Cod sursa (job #94831) | Cod sursa (job #2925518)
#include<iostream>
using namespace std;
const int MOD = 666013;
struct mat3x3
{
unsigned long long s1,s2,s3,m1,m2,m3,j1,j2,j3;
};
mat3x3 I3 = {1,0,0,0,1,0,0,0,1};
mat3x3 multiply(mat3x3 a,mat3x3 b)
{
mat3x3 nou;
nou.s1 = (a.s1 * b.s1 + a.s2 * b.m1 + a.s3 * b.j1) % MOD;
nou.s2 = (a.s1 * b.s2 + a.s2 * b.m2 + a.s3 * b.j2) % MOD;
nou.s3 = (a.s1 * b.s3 + a.s2 * b.m3 + a.s3 * b.j3) % MOD;
nou.m1 = (a.m1 * b.s1 + a.m2 * b.m1 + a.m3 * b.j1) % MOD;
nou.m2 = (a.m1 * b.s2 + a.m2 * b.m2 + a.m3 * b.j2) % MOD;
nou.m3 = (a.m1 * b.s3 + a.m2 * b.m3 + a.m3 * b.j3) % MOD;
nou.j1 = (a.j1 * b.s1 + a.j2 * b.m1 + a.j3 * b.j1) % MOD;
nou.j2 = (a.j1 * b.s2 + a.j2 * b.m2 + a.j3 * b.j2) % MOD;
nou.j3 = (a.j1 * b.s3 + a.j2 * b.m3 + a.j3 * b.j3) % MOD;
return nou;
}
mat3x3 fastpow(mat3x3 a,int b)
{
mat3x3 rez = I3;
while(b)
{
if(b & 1)
{
rez = multiply(rez,a);
}
a = multiply(a,a);
b >>= 1;
}
return rez;
}
void testcase()
{
int f1,f0,f2,a,b,c,n;
cin >> f0 >> f1 >> f2 >> a >> b >> c >> n;
mat3x3 iepuri = {a,b,c,1,0,0,0,1,0};
iepuri = fastpow(iepuri,n - 2);
int rez = (iepuri.s1 * f2 + iepuri.s2 * f1 + iepuri.s3 * f0) % MOD;
cout << rez << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
testcase();
}