- 理解矩阵乘法:http://www.ruanyifeng.com/blog/2015/09/matrix-multiplication.html
- 构造矩阵:根据递推构造矩阵用于快速幂
- https://blog.csdn.net/qian2213762498/article/details/82177690
- (附加知识:二次项展开https://baike.baidu.com/item/%E4%BA%8C%E9%A1%B9%E5%B1%95%E5%BC%80%E5%BC%8F/7078006?fr=aladdin )
- https://blog.csdn.net/Akatsuki__Itachi/article/details/80443939
- 快速幂 :https://www.cnblogs.com/wi1d3on/p/11321389.html
- 矩阵乘法模板:
inline mat matmul(mat x,mat y){ mat tmp; memset(tmp.f,0,sizeof(tmp.f)); For(i,1,2){ For(j,1,2){ For(k,1,2){ tmp.f[i][j]=(tmp.f[i][j]+x.f[i][k]%mo*y.f[k][j]%mo)%mo; } } } return tmp; }
- 矩阵快速幂模板:
inline void matpow(ll n){ mat f,tmp; f.f[1][1]=f.f[1][2]=f.f[2][1]=1,f.f[2][2]=0; memset(tmp.f,0,sizeof(tmp.f)); tmp.f[1][1]=tmp.f[1][2]=1; while(n){ if(n&1) tmp=matmul(tmp,f); f=matmul(f,f); n>>=1; } printf("%lld ",tmp.f[1][1]%mo); }
- 题目:
- P1962 斐波那契数列
- P4838 P哥破解密码