I found this algorithm on Wikipedia
function Matrix_ModExp(Matrix A, int b, int c)
if (b == 0):
return I // The identity matrix
if (b mod 2 == 1):
return (A * Matrix_ModExp(A, b - 1, c)) mod c
Matrix D := Matrix_ModExp(A, b / 2, c)
return (D * D) mod c
Can anyone explain to me the correctness proof and its time complexity? Thanks