Time Limit: 2 second(s) | Memory Limit: 32 MB |
Shanto is learning how to power up numbers and he found an efficient way to find k^{th} power of a matrix. He was quite happy with his discovery. Suddenly his sister Natasha came to him and asked him to find the summation of the powers. To be specific his sister gave the following problem.
Let A be an n x n matrix. We define A^{k} = A * A * ... * A (k times). Here, * denotes the usual matrix multiplication. You are to write a program that computes the matrix A + A^{2} + A^{3} + ... + A^{k}.
Shanto smiled and thought that it would be an easy one. But after a while he found that it's tough for him. Can you help him?
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with two integers n (1 ≤ n ≤ 30) and k (1 ≤ k ≤ 10^{9}). Each of the next n lines will contain n non-negative integers (not greater than 10).
For each case, print the case number and the result matrix. For each cell, just print the last digit. See the samples for more details.
Sample Input |
Output for Sample Input |
2 3 2 1 4 6 6 5 2 1 2 3 3 10 1 4 6 6 5 2 1 2 3 |
Case 1: 208 484 722 Case 2: 868 620 546 |
Developed and Maintained by
JANE ALAM JAN |
Copyright © 2012
LightOJ, Jane Alam Jan |