Matrix Quickpower Algorithm

Zhiyuan Xu Lv1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace Matrix{
#define mx ini.mat
int n,k;
struct ma{
int mat[MAXN][MAXN];
void init(){memset(mat,0,sizeof(mat));}
void pt(int num){
for (int i=0;i<=num;i++){
for (int j=0;j<=num;j++){
cout << mat[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
}ini;
inline ma mul(ma a, ma b){
ma c;
c.init();
for (int k=1;k<=n;k++){
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
c.mat[i][j] = (c.mat[i][j]+a.mat[i][k]*b.mat[k][j])%mod;
}
}
}
return c;
}
inline ma qpow(ma m, int num){
if (num==1) return m;
if (num%2==1) return mul(qpow(m,num-1),m);
ma tmp = qpow(m,num/2);
return mul(tmp,tmp);
}
inline void solve();
#undef mx
}
  • Title: Matrix Quickpower Algorithm
  • Author: Zhiyuan Xu
  • Created at : 2024-07-06 00:09:33
  • Updated at : 2024-07-06 00:28:33
  • Link: https://redefine.ohevan.com/Template/MatrixQP/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
Matrix Quickpower Algorithm