#P10502. Matrix Power Series

Matrix Power Series

题目描述

Givena n×nn×n matrix AA and apositive integer kk,find the sum S=A+A2+A3+...+AkS=A+A^2 +A^3 +...+A^k.

输入格式

The input contains exactly one test case. The first line of input contains three positive integers nn (n30n \le 30), kk (k109k \le 10^9) and mm (m<104m < 10^4). Then follow n lines each containing nn non negative integers below 32,768, giving AA’s elements in row-major order.

输出格式

Output the elements of SS modulo mm in the same way as AA is given.

2 2 4 
0 1 
1 1
1 2
2 3