Matrix Power Series Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 20125 Accepted: 8449 Description
Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak.
Input
The input contains exactly one test case. The first line of input contains three positive integers n (n ≤ 30), k (k ≤ 109) and m (m < 104). Then follow n lines each containing n nonnegative integers below 32,768, giving A’s elements in row-major order.
Output
Output the elements of S modulo m in the same way as A is given.
Sample Input
2 2 4 0 1 1 1 Sample Output
1 2 2 3
题目大意 : 就是求S %m;
题解 : 其实很容易知道A^k 之后只需加和就行了
但是直接加和还是不行 k的范围是在太大 会超时 所以就构造一个矩阵
因为S可以看成S=A(I+A(I+A(I+…A(I+A)))) (I是单位矩阵)
拿k=3举例S=A(I+A(I+A))
那么我们想,可不可以构造一个矩阵T使得TT(因为是k次幂)这样乘下去每次可以得到A(A+I)
那么肯定T有个两个元素就是A与I
那么假设:T={A I } I I 那么T=TT={AA+II AI+II} AI+II II+II 这样存在一个I(A+I)的式子 ,当T再乘以T的时候会出现A(A+I)