#C2333. Matrix Operations: Determinant and Inverse Calculation
Matrix Operations: Determinant and Inverse Calculation
Matrix Operations: Determinant and Inverse Calculation
You are given a square matrix A of size n × n. Your task is to compute the determinant of the matrix and, if the matrix is invertible, output its inverse. If the matrix is not invertible (i.e. its determinant is 0), output the message "Inverse does not exist".
Recall that for a 2×2 matrix:
[ \det(A)=a_{11}a_{22}-a_{12}a_{21} ]
For matrices of larger sizes, use any reliable method such as Gauss-Jordan elimination to compute the inverse.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer n (the size of the square matrix).
- The next n lines each contain n space-separated numbers (the elements of the matrix).
outputFormat
Print the determinant of the matrix on the first line. If the determinant is non-zero, print the inverse matrix in the following n lines where each line contains n space-separated numbers with 8 decimal places. If the matrix is not invertible (determinant is 0), print the message "Inverse does not exist" on the second line.
## sample2
4 6
3 8
14.0
0.57142857 -0.42857143
-0.21428571 0.28571429
</p>