#P3390. 【模板】矩阵快速幂

【模板】矩阵快速幂

Description

Given an n×nn \times n matrix AA, compute AkA^k.

Input Format

The first line contains two integers n,kn,k.
Then follow nn lines, each containing nn integers. In row ii, the jj-th number denotes Ai,jA_{i,j}.

Output Format

Output AkA^k.

There are nn lines in total, each containing nn numbers. The number in row ii and column jj denotes (Ak)i,j(A^k)_{i,j}. Each element is taken modulo 109+710^9+7.

2 1
1 1
1 1
1 1
1 1
3 5
1 2 3
4 5 6
7 8 9
121824 149688 177552
275886 338985 402084
429948 528282 626616

Hint

Constraints

For 100%100\% of the testdata, 1n1001 \le n \le 100, 0k10120 \le k \le 10^{12}, Ai,j1000|A_{i,j}| \le 1000.

Translated by ChatGPT 5