| 11 | |
| 12 | |
| 13 | class Matrix: |
| 14 | def __init__(self, arg: list[list] | int) -> None: |
| 15 | if isinstance(arg, list): # Initializes a matrix identical to the one provided. |
| 16 | self.t = arg |
| 17 | self.n = len(arg) |
| 18 | else: # Initializes a square matrix of the given size and set values to zero. |
| 19 | self.n = arg |
| 20 | self.t = [[0 for _ in range(self.n)] for _ in range(self.n)] |
| 21 | |
| 22 | def __mul__(self, b: Matrix) -> Matrix: |
| 23 | matrix = Matrix(self.n) |
| 24 | for i in range(self.n): |
| 25 | for j in range(self.n): |
| 26 | for k in range(self.n): |
| 27 | matrix.t[i][j] += self.t[i][k] * b.t[k][j] |
| 28 | return matrix |
| 29 | |
| 30 | |
| 31 | def modular_exponentiation(a: Matrix, b: int) -> Matrix: |
no outgoing calls
no test coverage detected