Sum of Matrix Powers
Time limit2sMemory limit512 MB
Given an N by N matrix A and K, compute A + A^2 + ... + A^K with all entries reduced modulo M.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Matrix, Math
- Solved
- No attempts yet
Problem
You are given an matrix and integers and . Reducing every entry of modulo is not hard.
This task asks for something else. Define the matrix as
and print every entry of modulo .
Input
The first line contains , , and separated by spaces (, , ).
Each of the next lines contains the matrix , integers per line separated by spaces ().
Output
Print lines. Each line holds the entries of the corresponding row of reduced modulo , separated by single spaces.
Hint
Every remainder must be at least and less than . Entries of can be negative, so watch the sign of the remainder.