Pagini recente » Cod sursa (job #421462) | Cod sursa (job #964516) | Cod sursa (job #321962) | Cod sursa (job #1925402) | Cod sursa (job #2382733)
#include <fstream>
#include <iostream>
#include <cstdio>
#define mod 666013
#define ll long long
using namespace std;
ll init[4][4];
ll rez[4][4];
int t,x,y,z,a,b,c,n;
void mult_mat( ll x[4][4],ll y[4][4])
{
int i,j,k;
ll aux[4][4];
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
aux[i][j]=0;
for(k=1;k<=3;k++)
{
aux[i][j]+=x[i][k]*y[k][j];
aux[i][j]%=mod;
}
}
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
x[i][j]=aux[i][j];
}
int main()
{
ios_base::sync_with_stdio(false);
ifstream t1("iepuri.in");
ofstream t2("iepuri.out");
int p,i,j;
t1>>t;
for(;t;t--)
{
t1>>x>>y>>z>>a>>b>>c>>n;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
init[i][j]=0;
rez[i][j]=0;
}
for(i=1;i<=3;i++) rez[i][i]=1;
init[1][1]=a; init[1][2]=b; init[1][3]=c;
init[2][1]=1; init[3][2]=1;
n-=2;
for(p=1;p<=n;p*=2)
{
if(p&n) mult_mat(rez,init);
mult_mat(init,init);
}
t2<< (1LL*rez[1][1]*z+1LL*rez[1][2]*y+1LL*rez[1][3]*x)%mod <<'\n';
}
return 0;
}