p3390

sshwy

2018-07-18 20:22:42

Personal

``` #include<bits/stdc++.h> #define P 1000000007 #define N 101 using namespace std; typedef long long ll; ll k; struct matrix{ ll n=0,c[N][N]={{0}}; matrix operator*(matrix tht){ matrix res; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=n;k++){ res.c[i][k]+=c[i][j]*c[j][k]; } } } return res; } matrix operator%(ll p){ matrix res; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ res.c[i][j]=c[i][j]%p; } } return res; } void read(){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%lld",&c[i][j]); } } } void write(){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ printf("%lld ",c[i][j]); } printf("\n"); } } }; matrix m; matrix ksm(matrix a,ll m){ if(m==1)return a; if(m==2)return a*a%P; matrix t=ksm(a,m/2); if(m%2)return ((t*t%P)*a)%P; else return t*t%P; } int main(){ scanf("%lld%lld",&m.n,&k); m.read(); m=ksm(m,k); m.write(); return 0; } ```