<p>Gauss–Jordan elimination algorithm has &nbsp;&nbsp; <a href="https://i.stack.imgur.com/VfTjJ.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VfTjJ.gif" alt="O(n^3)"></a> &nbsp;&nbsp; time complexity.</p>

<p>It can be shown that a divide and conquer algorithm that uses <a href="https://en.wikipedia.org/wiki/Invertible_matrix#Blockwise_inversion" rel="nofollow noreferrer">blockwise inversion</a> to invert an <a href="https://i.stack.imgur.com/8RXNF.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8RXNF.gif" alt="n x n"></a> matrix runs with the same time complexity as the matrix multiplication algorithm that is used internally.</p>

<p>So if you implement the <a href="https://en.wikipedia.org/wiki/Coppersmith%E2%80%93Winograd_algorithm" rel="nofollow noreferrer">Coppersmith–Winograd algorithm</a> for matrix multiplication you can achieve a time complexity of &nbsp;&nbsp; <a href="https://i.stack.imgur.com/ZJJw4.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZJJw4.gif" alt="O(2^{2.376})"></a> &nbsp;&nbsp; or <a href="https://arxiv.org/abs/1401.7714" rel="nofollow noreferrer">even better</a>.</p>

<p>In your <a href="https://i.stack.imgur.com/AHTTt.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AHTTt.gif" alt="Ax = B"></a> linear system, once you have found the matrix inverse <a href="https://i.stack.imgur.com/ONlTN.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ONlTN.gif" alt="A^{-1}"></a> of matrix <a href="https://i.stack.imgur.com/CZMvc.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CZMvc.gif" alt="A"></a>, the solution will be <a href="https://i.stack.imgur.com/ArEx9.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ArEx9.gif" alt="x = A^{-1}B"></a>.</p>
What is the shortest way to calculate and code linear algebra such as Ax=B
<p>i was wondering what is the shortest code(needed for contests like ACM) for calculating linear algebra such as Ax=B.
here's my java code for calculating Ax=B with Gaussian rule:</p>

<pre><code>public static void linearAlgebra(double[][] a , double[] b , double[] x , int n)
{
    for(int j = 0 ; j&lt;n ; j++)
    {
        for(int i = 0 ; i&lt;n ; i++)
        {
            if(j&lt;i)//lower triangle of A matrix
            {
                double factor = 1 ;
                int k=i-1;
                while(k&gt;=0)//find the Gaussian factor from the upper rows of the current row
                {
                    if(k==i)continue;
                    if(a[k][j]!=0)//if the upper rows same column is not zero
                    {
                        factor = (double)(-a[i][j])/a[k][j];
                        break;
                    }//if
                    k--;
                }//while checking the upper rows of the current row to find the Gaussian factor

                for(int m = 0 ; m&lt;n ; m++)
                {
                    a[i][m] += factor*a[k][m];// Gaussian factor
                }//for
                b[i] += factor*b[k];//do the same thing that we did with A to B
            }//if j&lt;i

        }//i

    }//j

    for(int i=n-1 ; i&gt;=0 ;i--)
    {
        //for example if we have 2*x2 + 3*x3 = b2 we already found x3 the rest is history :)
        double sum = 0 ;
        for(int j = i+1 ; j&lt;n ; j++)
        {
            sum += a[i][j]*x[j];
        }//j
        x[i] = (b[i]-sum)/a[i][i];//calculate x_i --&gt; for example the first loop will find x_n
    }//i



    //output the linear Algebra
    System.out.print("A's matrix after Gaussian:");
    System.out.println();
    for(int row = 0 ; row&lt;n ; row++)
    {
        for(int col = 0 ; col&lt;n ; col++)
        {
            System.out.print(a[row][col]+ " ");
        }
        System.out.println();
    }//i
    System.out.println();
    System.out.print("B's matrix after Gaussian:");
    for(int col = 0 ; col&lt;n ; col++)
    {
        System.out.println(b[col]);
    }//for
    System.out.println();
    System.out.print("x's vector is:");
    for(int col = 0 ; col&lt;n ; col++)
    {
        System.out.println(x[col]);
    }//for

}//linearAlgebra method
</code></pre>

<p>is there any faster rule or Gaussian is the best one to code if you need to code fast?
by the way this code can help those in need of calculating linear algebra by java. this code is tested but if it has any kind of bugs please let me know.</p>