Matrix Power Series
Easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given a n × n matrix A and a positive integer k, find the sum S = A + A^2
+ A^3
+ ... + A^k
.
Input
The first line contains three positive integers n (n ≤ 30), k (k ≤ 10^9
) and m (m < 10^4
). Then follow n lines each containing n non-negative integers below 32768, giving A's elements in row-major order.
Output
Print the elements of S modulo m in the same way as A is given.
Examples
Input #1
Answer #1
Submissions 523
Acceptance rate 31%