Pagini recente » Cod sursa (job #3314694) | Cod sursa (job #2113770) | Cod sursa (job #3350537) | Cod sursa (job #2190184) | Cod sursa (job #3352194)
#include <fstream>
using namespace std;
ifstream cin("iepuri.in");
ofstream cout("iepuri.out");
int rez[4][4],baza[4][4];
void copierematricerez(int nm[4][4])
{
for(int y=1;y<=3;y++)
for(int x=1;x<=3;x++)
rez[y][x]=nm[y][x];
}
void copierematricebaza(int nm[4][4])
{
for(int y=1;y<=3;y++)
for(int x=1;x<=3;x++)
baza[y][x]=nm[y][x];
}
void putere(int exp)
{
int aux[4][4];
while(exp>0) {
for(int y=1;y<=3;y++)
for(int x=1;x<=3;x++)
aux[y][x]=0;
if(exp%2==0) {
for(int y=1;y<=3;y++)
for(int x=1;x<=3;x++)
for(int k=1;k<=3;k++)
aux[y][x]+=baza[k][x]*baza[y][k]*1LL%666013;
exp/=2;
copierematricebaza(aux);
}
else {
for(int y=1;y<=3;y++)
for(int x=1;x<=3;x++)
for(int k=1;k<=3;k++)
aux[y][x]+=baza[y][k]*rez[k][x]*1LL%666013;
exp--;
copierematricerez(aux);
}
}
}
int main()
{
int t,n,a,b,c,x,y,z;
cin>>t;
for(int n2=1;n2<=t;n2++) {
cin>>x>>y>>z>>a>>b>>c>>n;
baza[1][1]=baza[1][3]=baza[2][1]=baza[2][2]=0;
baza[1][2]=baza[2][3]=1;
baza[3][1]=c;
baza[3][2]=b;
baza[3][3]=a;
rez[1][2]=rez[1][3]=rez[2][1]=rez[2][3]=rez[3][1]=rez[3][2]=0;
rez[1][1]=rez[2][2]=rez[3][3]=1;
putere(n-2);
unsigned long long rezultatdupamitozanebunaaiepurilor=((x*rez[3][1]*1LL)%666013+(y*rez[3][2]*1LL)%666013+(z*rez[3][3]*1LL)%666013)%666013;
cout<<rezultatdupamitozanebunaaiepurilor<<'\n'; /// ???
}
return 0;
}