class Polynomial implements IReadDataBlock {

    public static Division divide(final Polynomial num, final Polynomial denom) {
        int n = num.getDegree(), nv = denom.getDegree();
        if (nv > n) {
            return new Division(num, Polynomial.ZERO);
        }
        double[] r = new double[n + 1];
        double[] q = new double[n + 1];

        for (int j = 0; j <= n; ++j) {
            r[j] = num.get(j);
            q[j] = 0.0;
        }
        for (int k = n - nv; k >= 0; --k) {
            q[k] = r[nv + k] / denom.get(nv);
            for (int j = nv + k - 1; j >= k; j--) {
                r[j] -= q[k] * denom.get(j - k);
            }
        }
        Polynomial m_q = Polynomial.of(Arrays.copyOf(q, n - nv + 1));
        Polynomial m_r = nv > 0 ? Polynomial.of(Arrays.copyOf(r, nv)).adjustDegree() : Polynomial.ZERO;
        return new Division(m_r, m_q);
    }

    private  Polynomial(final double[] coefficients, final int degree);

}