首页 > 其他 > 详细

矩阵快速幂板子

时间:2018-04-08 20:37:38      阅读:237      评论:0      收藏:0      [点我收藏+]
 1 struct Matrix
 2 {
 3     int a[3][3];
 4     Matrix()
 5     {
 6         memset(a,0,sizeof(a));
 7     }
 8     void init()
 9     {
10         for(int i=0;i<3;i++)
11             for(int j=0;j<3;j++)
12                 a[i][j]=(i==j);
13     }
14     Matrix operator * (const Matrix &B)const
15     {
16         Matrix C;
17         for(int i=0;i<3;i++)
18             for(int j=0;j<3;j++)
19                 for(int k=0;k<3;k++)
20                     C.a[i][j]=(C.a[i][j]+1LL*a[i][k]*B.a[k][j])%Mod;
21         return C;
22     }
23     Matrix operator ^ (const ll &p)const
24     {
25         Matrix A=(*this),res;
26         res.init();
27         ll t=p;
28         while(t)
29         {
30             if(t&1)res=res*A;
31             A=A*A;
32             t>>=1;
33         }
34         return res;
35     }
36 }M[8];

 

矩阵快速幂板子

原文:https://www.cnblogs.com/CJLHY/p/8747253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!