Skip to content

Instantly share code, notes, and snippets.

View monsij's full-sized avatar

Monsij Biswal monsij

View GitHub Profile
@monsij
monsij / fastmatexpo.cpp
Last active April 17, 2019 18:27
Fast matrix exponentiation with Modulo
//These are two functions which aid in raising a matrix data[][] to the power n using fast exponentiation techniques.
/*
Prerequisites:
// The matrix must be a 2x2 matrix.
1. data[2][2] ->The matrix which is required to be raised to nth power
2. result[2][2] ->Initially make it equal to a 2x2 identity matrix.This matrix contains the required result.
3. n -> The exponent
4. Also include --> #define ll long long int
5. Also include --> #define mod_12 1000000007
<--- Note-All the above variables must be global --->