矩阵快速幂

struct Matrix{ long long  arr[105][105];}  init, unit;
long long k, ret, mod = 1e9 + 7;
long long a[105];
int n;

Matrix Mul(Matrix a, Matrix b){
    Matrix c;
    rep(i, 1, n) rep(j, 1, n){
        c.arr[i][j] = 0;
        rep(k, 1, n) (c.arr[i][j] += (a.arr[i][k] * b.arr[k][j] % mod)) %= mod;
    }
    return c;
}

Matrix Pow(Matrix a, long long  k){
    Matrix ret(unit); for (; k; k >>= 1, a = Mul(a, a)) if (k & 1) ret = Mul(ret, a); return ret;
} 
原文地址:https://www.cnblogs.com/chinacwj/p/8277502.html