'Returns the GCD of ``f`` and ``g`` and their cofactors.
Returns polynomials ``(h, cff, cfg)`` such that ``h = gcd(f, g)``, and
``cff = quo(f, h)`` and ``cfg = quo(g, h)`` are, so called, cofactors
of ``f`` and ``g``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> Poly(x**2 - 1, x).cofactors(Poly(x**2 - 3*x + 2, x))
(Poly(x - 1, x, domain=\'ZZ\'),
Poly(x + 1, x, domain=\'ZZ\'),
Poly(x - 2, x, domain=\'ZZ\'))'

def cofactors(f, g):

    (_, per, F, G) = f._unify(g)
    if hasattr(f.rep, 'cofactors'):
        (h, cff, cfg) = F.cofactors(G)
    else:
        raise OperationNotSupported(f, 'cofactors')
    return (per(h), per(cff), per(cfg))
