zoukankan      html  css  js  c++  java
  • 矩阵快速幂板子

     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];
  • 相关阅读:
    基于typora编写Markdown文档
    VMware Workstation常见的故障处理
    VMware Workstation产品常用的快捷键
    2
    1
    9
    8
    7
    6
    5
  • 原文地址:https://www.cnblogs.com/CJLHY/p/8747253.html
Copyright © 2011-2022 走看看