#P2455. Solving a System of Linear Equations
Solving a System of Linear Equations
Solving a System of Linear Equations
Given an \(n\times n\) system of linear equations:
$$\begin{cases} a_{1,1}x_1+a_{1,2}x_2+\cdots+a_{1,n}x_n=b_1\\ a_{2,1}x_1+a_{2,2}x_2+\cdots+a_{2,n}x_n=b_2\\ \vdots \\ a_{n,1}x_1+a_{n,2}x_2+\cdots+a_{n,n}x_n=b_n \end{cases} $$Your task is to determine the solution of the system. If there is a unique solution, output the values of \(x_1,x_2,\dots,x_n\) (each formatted to 6 decimal places) separated by a space. If the system has infinitely many solutions, output Infinite solutions
. If there is no solution, output No solution
.
inputFormat
The first line contains an integer \(n\) representing the number of equations and unknowns. The following \(n\) lines each contain \(n+1\) space-separated numbers. The first \(n\) numbers of each line represent the coefficients \(a_{i,1}, a_{i,2}, \dots, a_{i,n}\) and the last number is the constant \(b_i\).
For example:
3 1 0 0 1 0 1 0 2 0 0 1 3
outputFormat
If the system has a unique solution, output the solution values \(x_1, x_2, \dots, x_n\) in order, each formatted with 6 decimal places and separated by a space. If the system has infinitely many solutions, output Infinite solutions
. If there is no solution, output No solution
.
sample
3
1 0 0 1
0 1 0 2
0 0 1 3
1.000000 2.000000 3.000000