Matrix and Fibonacci Sum
Time limit5sMemory limit512 MB
Compute the sum of Fibonacci numbers with linearly growing indices times increasing powers of a K×K matrix, modulo a prime, for N up to 10^1000.
- Level
Hard9 of 10
- Topics
- Matrix, Math, Divide and conquer, Number theory
- Solved
- No attempts yet
Problem
You are given a matrix and nonnegative integers , , and . Let denote the entry in row and column of .
Define the matrix as follows.
[ S = \sum_{i=0}^{N}{F_{a+i \cdot d} \cdot M^i}. ]
Here, is the identity matrix. The Fibonacci numbers are defined by , , and, for , .
Compute the matrix .
Input
The first line contains , , , and .
The next lines contain the entries of matrix . The -th of these lines contains , , ..., , separated by spaces.
Output
Print lines containing the entries of matrix modulo .
On the -th line, print , , ..., separated by spaces.