Pagini recente » Cod sursa (job #1221318) | Istoria paginii runda/preoji_11-12_2 | Cod sursa (job #1462685) | Cod sursa (job #1633246) | Cod sursa (job #2495844)
#include <bits/stdc++.h>
#define ll long long
#define mod 666013
using namespace std;
ifstream fin ("iepuri.in");
ofstream fout ("iepuri.out");
ll t, x, y, z, a, b, c, n, m[3][3], r[3][3];
void init()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
m[i][j]=r[i][j]=0;
}
void inm (ll r[3][3], ll m[3][3])
{
ll aux[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
aux[i][j]=0;
for(int k=0;k<3;k++)
aux[i][j]+=r[i][k]*m[k][j];
aux[i][j]%=mod;
}
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
r[i][j]=aux[i][j];
}
int main()
{
fin >> t;
while(t--)
{
fin >> x >> y >> z >> a >> b >> c >> n;
n-=2;
init();
for(int i=0;i<3;i++)
r[i][i]=1;
m[1][0]=m[2][1]=1;
m[0][2]=c, m[1][2]=b, m[2][2]=a;
while(n)
{
if(n%2)
inm(r, m);
inm(m, m);
n/=2;
}
fout << (x*r[0][2]+y*r[1][2]+z*r[2][2])%mod << '\n';
}
return 0;
}