Matrix Class and Fast Power
Hard · Classes
Finish the Matrix class for SQUARE matrices of integers:
- static identity(size) returns the identity matrix (1 on the diagonal, 0 elsewhere).
- multiply(other) returns a NEW matrix with the product this × other.
- pow(exponent) returns this raised to a non-negative integer power. pow(0) is the identity.
pow must use fast exponentiation (square-and-multiply), so an exponent like 1000000000 finishes instantly.
The driver matrixPower(rows, exponent) is already written.