Code:
#include <bits/stdc++.h>
using namespace std;
#define maxn 110
#define mod 1000000007
#define lo long long
lo n, k;
struct node {
lo a[ maxn] [ maxn] ;
node ( ) {
memset ( a, 0 , sizeof ( a) ) ;
}
} e, anns;
inline node cf_ ( node x, node y) {
node sum;
for ( int i= 1 ; i<= n; i++ ) {
for ( int j= 1 ; j<= n; j++ ) {
for ( int k= 1 ; k<= n; k++ ) {
sum. a[ i] [ j] + = ( x. a[ i] [ k] * y. a[ k] [ j] % mod) ;
sum. a[ i] [ j] % = mod;
}
}
}
return sum;
}
inline node pow_ ( node x, lo y) {
node ans;
for ( int i= 1 ; i<= n; i++ ) ans. a[ i] [ i] = 1 ;
while ( y) {
if ( y& 1 ) ans= cf_ ( ans, x) ;
x= cf_ ( x, x) ;
y>>= 1 ;
}
return ans;
}
inline void init_ ( ) {
freopen ( "a.txt" , "r" , stdin ) ;
}
inline lo read_ ( ) {
lo x= 0 , f= 1 ;
char c= getchar ( ) ;
while ( c< '0' || c> '9' ) {
if ( c== '-' ) f= - 1 ;
c= getchar ( ) ;
}
while ( c>= '0' && c<= '9' ) {
x= x* 10 + c- '0' ;
c= getchar ( ) ;
}
return x* f;
}
inline void readda_ ( ) {
n= read_ ( ) ; k= read_ ( ) ;
lo pp;
for ( int i= 1 ; i<= n; i++ ) {
for ( int j= 1 ; j<= n; j++ ) {
pp= read_ ( ) ;
e. a[ i] [ j] = pp;
}
}
}
inline void print_ ( ) {
for ( int i= 1 ; i<= n; i++ ) {
for ( int j= 1 ; j<= n; j++ ) {
printf ( "%lld " , anns. a[ i] [ j] % mod) ;
}
printf ( "\n" ) ;
}
}
inline void work_ ( ) {
anns= pow_ ( e, k) ;
print_ ( ) ;
}
int main ( ) {
init_ ( ) ;
readda_ ( ) ;
work_ ( ) ;
return 0 ;
}