矩阵乘法模板
#include<bits/stdc++.h> using namespace std; int mod ; struct Matrix { int n , m ; int mat[4][4] ; int * operator [] (int x) { return mat[x] ; } } ; Matrix operator * (Matrix &x , Matrix &y) { Matrix res ; res.n = x.n , res.m = y.m ; memset (res.mat , 0 , sizeof(res.mat) ) ; for (int i = 0 ; i < x.n ; i ++) { for (int j = 0 ; j < y.m ; j ++) { for (int k = 0 ; k < x.m ; k ++) { int tmp = (int) (1ll*x[i][k] * y[k][j] % mod ) ; res[i][j] = (res[i][j] + tmp) % mod ; } } } return res ; } int main () { Matrix x , y ; x = {2 , 2 , {{1 , 0} , {2, 3}} } ; y = {2 , 2 , {{2 , 1} , {3, 4}} } ; mod = 1000 ; Matrix z = x * y ; for (int i = 0 ; i < 2 ; i ++) { for (int j = 0 ; j < 2 ; j++) { cout << z[i][j] << " " ; } cout << endl ; } return 0 ; }