문제1621--FastMatrixMultiplication

1621: FastMatrixMultiplication

실행시간 제한: 1 Sec  메모리사용 제한: 128 MB
제출: 210  통과: 24
[제출] [채점기록] [묻고답하기]

문제 설명

Fast Matrix Multiplication can be applied to many areas.

Given a r*r matrix M, and integer n, print Mn.

Elements of the result could be very large, so please print each element modular 1,000,000,007.

 

입력 설명

The first line of the input gives the number of test cases, T (1 <= T <= 200).

Each test case starts with a line consists of two integers r and n. r will be between 1 and 30, inclusive, and n will be between 0 and 1,000,000,000, inclusive.

Next r lines will each contain r numbers, which will be between 0 and 1,000,000,006, inclusive. j-th element of i-th line represent Mij.

 

 

 

출력 설명

For each test case, print r lines containing r integers representing Mnij.

 

 

 

입력 예시 Copy

2
3 2
0 0 1
0 1 0
1 0 0
2 40
2 2
2 2

출력 예시 Copy

1 0 0
0 1 0
0 0 1
248320570 248320570
248320570 248320570

출처/분류