Pagini recente » Cod sursa (job #176744) | Cod sursa (job #2362458) | Cod sursa (job #1725518) | Cod sursa (job #1706860) | Cod sursa (job #447715)
Cod sursa(job #447715)
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
#define mod 666777;
long long T,X,Y,Z,A,B,C,N,logi[100];
ofstream fout("iepuri.out");
void solve()
{ long long a[100][100],sol[100][100],aux[100][100];
int i,j,k,ii,jj,kk;
memset(a,0,sizeof(a));
memset(sol,0,sizeof(sol));
memset(aux,0,sizeof(aux));
a[2][1]=a[3][2]=1;
a[1][1]=A;
a[1][2]=B;
a[1][3]=C;
sol[1][1]=1;
sol[2][2]=1;
sol[3][3]=1;
for(i=0;(1<<i)<=N-2;i++)
{memset(aux,0,sizeof(aux));
if(((1<<i)&(N-2))>0)
{for(ii=1;ii<=3;ii++)
for(jj=1;jj<=3;jj++)
{aux[ii][jj]=0;
for(kk=1;kk<=3;kk++)
aux[ii][jj]=(aux[ii][jj]+sol[ii][kk]*a[kk][jj])%mod;
}
for(ii=1;ii<=3;ii++)
for(jj=1;jj<=3;jj++)
sol[ii][jj]=aux[ii][jj];
}
memset(aux,0,sizeof(aux));
for(ii=1;ii<=3;ii++)
for(jj=1;jj<=3;jj++)
{aux[ii][jj]=0;
for(kk=1;kk<=3;kk++)
aux[ii][jj]=(aux[ii][jj]+a[ii][kk]*a[kk][jj])%mod;
}
for(ii=1;ii<=3;ii++)
for(jj=1;jj<=3;jj++)
a[ii][jj]=aux[ii][jj]%666777;
}
fout<<sol[1][1]*Z+sol[1][2]*Y+sol[1][3]*X<<"\n";
}
void cit()
{long long i;
ifstream fin("iepuri.in");
fin>>T;
for(i=1;i<=T;i++)
{fin>>X>>Y>>Z>>A>>B>>C>>N;
solve();
}
fin.close();
}
int main()
{
cit();
fout.close();
return 0;
}