Rare
0/9
Matrix Exponentiation
Authors: Benjamin Qi, Neo Wang
Repeatedly multiplying a square matrix by itself.
Prerequisites
Resources | ||||
---|---|---|---|---|
CP2 | ||||
CPH | ||||
CF | video + problemset | |||
CF | interesting applications of mat exp | |||
Mostafa | powerpoint of matrix exponentiation |
Example - Fibonacci
Focus Problem – read through this problem before continuing!
The fibonacci numbers are defined by the following matrix relation
Proof by Induction
The fibonacci numbers are defined as follows:
Base case ():
Induction step ():
The base case is true, and the induction step is true. Therefore the formula holds for all .
Implementation
Time complexity:
#include <bits/stdc++.h>using namespace std;using ll = long long;const ll MOD = 1e9 + 7;using Matrix = array<array<ll, 2>, 2>;Matrix mul(Matrix a, Matrix b) {
Problems
Status | Source | Problem Name | Difficulty | Tags | |
---|---|---|---|---|---|
CSES | Easy | Show TagsExponentiation, Matrix | |||
CSES | Easy | Show TagsExponentiation, Matrix | |||
CF | Easy | Show TagsExponentiation, Matrix | |||
CF | Normal | Show TagsExponentiation, Matrix, PURS | |||
Baltic OI | Normal | Show TagsExponentiation, Matrix | |||
Balkan OI | Normal | Show TagsExponentiation, Matrix | |||
DMOJ | Normal | Show TagsExponentiation, Matrix | |||
Plat | Hard | Show TagsExponentiation, Matrix |