#include<stdio.h> #include<string.h> const int N=2; const int p2=10000; struct Mat{ int mat[N+1][N+1]; }; Mat operator *(Mat a,Mat b) { Mat c; memset(c.mat,0,sizeof(c.mat));//清零 for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) for(int k=1;k<=N;k++) c.mat[i][j]=(c.mat[i][j]+(a.mat[i][k]*b.mat[k][j])%p2)%p2; return c; } Mat operator ^(Mat a,int b) { Mat c; for(int i=1;i<=N;++i) for(int j=1;j<=N;++j) c.mat[i][j]=(i==j);//构建单位举证 for(;b;b>>=1) { if(b&1) c=c*a; a=a*a; } return c; } int main(){ Mat a; a.mat[1][1]=1; a.mat[1][2]=2; a.mat[2][1]=3; a.mat[2][2]=4; Mat b = a^2; for(int i=1;i<=N;++i){ for(int j=1;j<=N;++j) printf("%d ",b.mat[i][j]); puts(""); } return 0; }