luogu#P10775. BZOJ4162 shlw loves matrix II

BZOJ4162 shlw loves matrix II

Background

Note: This problem is not a matrix fast exponentiation template problem.

Problem Description

Given a matrix MM, compute MnM^n, and output each element modulo 109+710^9+7.

Input Format

The first line contains two integers n,kn, k, where nn is given in binary and may contain leading zeros.

The next kk lines describe a k×kk \times k matrix MM.

Output Format

Output the matrix required in the description, using the same format as the input.

010 3
5 9 5
5 4 0
8 8 8
110 121 65
45 61 25
144 168 104

Hint

For 100%100\% of the testdata, 1n21041 \le n \le 2^{10^4}, 1k501 \le k \le 50, and 0Mi,j<109+70 \le M_{i,j} < 10^9+7.

Translated by ChatGPT 5