private static final void coeffs (long[][] mat, int mA, int mB, long[] pA, long[] pB) throws Exception {
        long[] c = new long [mA + mB]; 
        // store the solution to the linear system in c
        int i, j;
        for (i = mA + mB - 1; i >= 0; i--) {
            c[i] = PF.div(mat[i][mA + mB], mat[i][i]);
            for (j = 0; j < i; j++) // subtract out the coefficient from the previous entries
                mat[j][mA + mB] = PF.sub(mat[j][mA + mB], PF.mul(c[i], mat[j][i]));
        }
        
        for (i = 0; i < mA; i++) pA[i] = c[i];
        pA[mA] = 1L;
        for (i = mA + 1; i < pA.length; i++) pA[i] = 0;
        
        for (i = 0; i < mB; i++) pB[i] = c[mA + i];
        pB[mB] = 1L;
        for (i = mB + 1; i < pB.length; i++) pB[i] = 0;
    }