#include<stdio.h> #include<iostream> usingnamespacestd; constlonglongint maxn = 101, mod = 1000000007; structmatrix { longlongint s[maxn][maxn]; }; longlong a, b; matrix res, ans; matrix mul(matrix A, matrix B, longlongint n)//矩阵乘法,注意矩阵乘法无交换律 { matrix C; for (longlongint i = 1; i <= n; i++) for (longlongint j = 1; j <= n; j++) C.s[i][j] = 0;
for (longlongint i = 1; i <= n; i++) for (longlongint j = 1; j <= n; j++) for (longlongint k = 1; k <= n; k++) C.s[i][j] += A.s[i][k] * B.s[k][j]%mod;
return C; } voidquick(longlongint y, longlongint n)//快速幂 {
res = ans; while (y) { if (y & 1) ans = mul(ans, res, n); res = mul(res, res, n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ans.s[i][j] %= mod; res.s[i][j] %= mod; } } y = y >> 1; } }
intmain() { longlongint n, y; scanf("%lld%lld", &n, &y); --y; matrix ans0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> ans.s[i][j]; quick(y, n); //ans0 = mul(ans, ans0, n); /* for(int i=1 ;i<3 ;i++) { for(int j=1 ;j<3 ;j++) printf("%lld ",ans0.s[i][j]); puts(""); }*/ for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout<< ans.s[i][j]%mod<< ' '; puts(""); } return0; }