Polynomial of a matrix
Work modulo \(p=1\,000\,000\,007\). Given an (n\times n) matrix (A) and
\[
f(x)=c_0+c_1x+\cdots+c_dx^d,
\]
compute
\[
f(A)=c_0I+c_1A+\cdots+c_dA^d\pmod p.
\]
Input
The first line contains (n,d). The next (n) lines contain (A). The final
line contains (c_0,c_1,\ldots,c_d).
Output
Print (f(A)) as (n) rows of (n) integers modulo (p).
Constraints
- \(1\le n\le 50\)
- \(0\le d\le 50\)
- Every matrix and polynomial coefficient is an integer in \([0,p)\)