MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / modular_exponentiation

Function modular_exponentiation

maths/matrix_exponentiation.py:31–38  ·  view source on GitHub ↗
(a: Matrix, b: int)

Source from the content-addressed store, hash-verified

29
30
31def modular_exponentiation(a: Matrix, b: int) -> Matrix:
32 matrix = Matrix([[1, 0], [0, 1]])
33 while b > 0:
34 if b & 1:
35 matrix *= a
36 a *= a
37 b >>= 1
38 return matrix
39
40
41def fibonacci_with_matrix_exponentiation(n: int, f1: int, f2: int) -> int:

Callers 1

Calls 1

MatrixClass · 0.70

Tested by

no test coverage detected