RREF
InterviewTime limit0.5sMemory limit1024 MB
Compute the reduced row echelon form of an N by M matrix of rational numbers, printing each entry as a reduced fraction.
- Level
Medium4 of 10
- Topics
- Math, Implementation, Matrix, Number theory
- Solved
- No attempts yet
Problem
Output the RREF of the given matrix.
RREF (Reduced Row Echelon Form) is a matrix with the following properties.
- Every row whose entries are all (a zero row) is below every row that is not (a row with a nonzero entry).
- The leading coefficient of every nonzero row is .
- The leading coefficient of every nonzero row is to the right of the leading coefficient of the row above it.
- In the column of the leading coefficient of every nonzero row, all other entries are .
Input
The first line gives and , the dimensions of the matrix. ()
The next lines each contain rational numbers. Each rational number is given as a fraction / in lowest terms. (, )
If , only is given, and if , the sign is omitted.
Output
Output the RREF of the given matrix.
Print each entry as a fraction / in lowest terms. If , print only , and if , omit the sign.
Hint
RREF stands for Reduced Row Echelon Form.