Pagini recente » Cod sursa (job #2834986) | Cod sursa (job #1488421) | Cod sursa (job #3265113) | Cod sursa (job #1552409) | Cod sursa (job #2464685)
#include <iostream>
#include <fstream>
using namespace std;
const int mod=666013;
class Matrice
{
private:
long long int a[4][4],n,m;
public:
Matrice(const int n,const int m,const int val=0)
{
this->n=n;
this->m=m;
for (int i=1;i<=this->n;i++)
for (int j=1;j<=this->m;j++)
this->a[i][j]=val;
}
void setValue(int i,int j,int val)
{
if (i>=1&&i<=this->n&&j>=1&&j<=this->m)
this->a[i][j]=val;
}
int getN()
{
return this->n;
}
int getM()
{
return this->m;
}
int getVal(int i,int j)
{
return this->a[i][j];
}
virtual bool samesize(Matrice *m1,Matrice *m2)
{
if (m1->n==m2->n&&m1->m==m2->m)
return true;
return false;
}
Matrice& operator=(Matrice *m)
{
if (samesize(this, m))
for (int i=1;i<=this->n;i++)
for (int j=1;j<=this->m;j++)
this->a[i][j]=m->a[i][j];
return *this;
}
Matrice& operator*=(Matrice *m)
{
if (this->getM()==m->getN())
{
Matrice c(this->n,m->m,0);
for (int i=1; i<=this->n; i++)
for (int j=1; j<=m->m; j++)
for (int k=1; k<=this->m; k++)
c.a[i][j]=(c.a[i][j]+1LL*this->a[i][k]*m->a[k][j])%mod;
*this=c;
}
return *this;
}
Matrice& operator*=(int val)
{
for (int i=1;i<=this->n;i++)
for (int j=1;j<=this->m;j++)
this->a[i][j]*=val;
return *this;
}
Matrice operator*(Matrice &m2)
{
Matrice m3=*this;
m3*=&m2;
return m3;
}
Matrice operator*(int val)
{
Matrice m3=*this;
m3*=val;
return m3;
}
};
int main()
{
ifstream fin ("iepuri.in");
ofstream fout ("iepuri.out");
int exe;
fin>>exe;
for (int q=0;q<exe;q++)
{
int v1,v2,v3,e1,e2,e3,k;
fin>>v1>>v2>>v3>>e1>>e2>>e3>>k;
Matrice c(3,3),z(3,3);
/*c.setValue(1, 1, 1);
c.setValue(1, 2, 1);*/
c.setValue(1, 1, e1);
c.setValue(1, 2, e2);
c.setValue(1, 3, e3);
z.setValue(1, 1, v1);
z.setValue(2, 1, v2);
z.setValue(3, 1, v3);
z.setValue(1, 2, 1);
z.setValue(2, 3, 1);
k-=2;
while(k>1)
if (k%2==0)
{
z*=&z;
k/=2;
}
else
{
c*=&z;
k--;
}
c*=&z;
fout<<c.getVal(1, 1)<<'\n';
}
return 0;
}