矩阵乘法
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#define w 2005
struct Matrix
{
int x, y;
int num[5][5];
Matrix(int xx, int yy)
{
x = xx;
y = yy;
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
num[i][j] = 0;
}
};
Matrix operator*(Matrix numa, Matrix numb)
{
Matrix numc(numa.x, numb.y);
int i, j, k;
for (i = 0; i < numc.x; i++)
for (j = 0; j < numc.y; j++)
for (k = 0; k < numa.y; k++)
numc.num[i][j] = (numc.num[i][j] + numa.num[i][k] * numb.num[k][j]) % w;
return numc;
}
Matrix operator ^(Matrix numa, int x)
{
Matrix numc(numa.x, numa.y);
int i;
for (i = 0; i < numa.x; i++)
numc.num[i][i] = 1;
for (; x; x >>= 1)
{
if (x & 1)
numc = numc * numa;
numa = numa * numa;
}
return numc;
}