Inverse Matrix
Time limit1sMemory limit128 MB
Invert the given N by N matrix modulo 998244353 and print no inverse when the matrix is singular.
- Level
Medium4 of 10
- Topics
- Matrix, Number theory
- Solved
- No attempts yet
Problem
is a prime. Given an integer matrix , write a program that computes the inverse of modulo .
A matrix with is called the inverse of and is written . Two matrices are congruent when the entries in every matching position are congruent modulo . is the identity matrix, where for and .
is prime, so the inverse is unique whenever it exists. It exists exactly when the determinant of is not a multiple of . A matrix whose determinant over the integers is nonzero still has no inverse modulo if that determinant is divisible by .
Input
The first line contains the size of the matrix. ()
Each of the next lines describes one row of and contains integers. The absolute value of each integer is at most 1,000. A negative entry is read as its residue modulo .
Output
If the inverse of modulo exists, print over lines. Each line holds integers separated by a single space, and every integer is at least and less than .
If the inverse does not exist, print no inverse.