Problems > Matrix Determinant mod p > Editorial

Matrix Determinant mod p — Solution & Editorial

Back to the Problem

Fraction-free is unnecessary over a field: run Gaussian elimination with modular inverses, tracking the sign from row swaps; the determinant is the product of pivots.

Complexity: O(N³)

Watch out: A zero column below the pivot with no available swap means the determinant is 0.