矩阵快速幂+倍增法(纯模板)

来源:互联网 发布:消防接线网络 编辑:程序博客网 时间:2024/06/05 16:47
Mat power(Mat M,int P){    Mat tot(1);    while (P){        if (P&1) tot=tot*M;        P>>=1,M=M*M;    }    return tot;}
Mat count(Mat M,int P){    Mat M0,E(1),M1=E;    while (P){        if (P&1) M0=M0+M1*power(M,P);        P>>=1;        M1=M1*(E+power(M,P));    }    return M0;}

原创粉丝点击