矩阵乘法+快速幂模板

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=110,maxm=110,m=1e9+7;
int n,p,sz;
struct mat{
	int a[maxn][maxm];
	mat() { memset(a, 0, sizeof a); }
	mat operator*(const mat &t) const{
		mat res;
		int r;
		for(int i=1;i<=n;i++)
		   for(int k=1;k<=n;k++){
		   		r=a[i][k];
		   		for(int j=1;j<=n;j++)
		   		  res.a[i][j]=(res.a[i][j]+t.a[k][j]*r)%m;
		   }
		return res;
	}
}ans,base;
void qbow(int b){
	while(b){
		if(b%2) ans=ans*base;
		base=base*base;
		b>>=1;
	}
}
posted @ 2025-08-09 15:20  _dlwlrma  阅读(4)  评论(0)    收藏  举报