#P10502. Matrix Power Sum

    ID: 12517 Type: Default 1000ms 256MiB

Matrix Power Sum

Matrix Power Sum

Given an n×n matrix A and a positive integer k, calculate the sum:

\(S = A + A^2 + A^3 + \cdots + A^k\)

The matrix multiplication is the standard one. You are required to output the resulting matrix S after summing up all matrix powers from 1 to k.

inputFormat

The first line contains two integers n and k separated by space, where n is the size of the matrix and k is the number of powers to sum.

Each of the next n lines contains n space-separated integers, representing the rows of the matrix A.

outputFormat

Output the matrix S in n lines. Each line should contain n space-separated integers representing one row of the resulting matrix.

sample

2 3
1 2
3 4
45 66

99 144

</p>