Sum of matrix powers
Time limit2sMemory limit512 MB
Compute A + A^2 + ... + A^B for an N by N matrix A, with B up to 1e11, printing every entry modulo 1000.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Matrix, Recursion
- Solved
- No attempts yet
Problem
You are given an matrix . Write a program that computes the matrix obtained by adding every power of from the first up to the th:
The entries can grow very large, so print each entry of modulo 1,000.
Input
The first line contains the matrix size and the exponent bound , separated by a space. (, )
Each of the next lines contains entries of , separated by spaces. Every entry is 0 or a natural number at most 1,000.
Output
Print the matrix on lines. Line contains the entries of row of , each taken modulo 1,000 and separated by a space.