'Return the tuple (R, self/R) where R is the positive Rational
extracted from self. If radical is True (default is False) then
common radicals will be removed and included as a factor of the
primitive expression.
Examples
>>> from sympy import sqrt
>>> (3 + 3*sqrt(2)).as_content_primitive()
(3, 1 + sqrt(2))
Radical content can also be factored out of the primitive:
>>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
(2, sqrt(2)*(1 + 2*sqrt(5)))
See docstring of Expr.as_content_primitive for more examples.'

def as_content_primitive(self, radical=False, clear=True):

    (con, prim) = self.func(*[_keep_coeff(*a.as_content_primitive(radical=radical, clear=clear)) for a in self.args]).primitive()
    if ((not clear) and (not con.is_Integer) and prim.is_Add):
        (con, d) = con.as_numer_denom()
        _p = (prim / d)
        if any((a.as_coeff_Mul()[0].is_Integer for a in _p.args)):
            prim = _p
        else:
            con /= d
    if (radical and prim.is_Add):
        args = prim.args
        rads = []
        common_q = None
        for m in args:
            term_rads = defaultdict(list)
            for ai in Mul.make_args(m):
                if ai.is_Pow:
                    (b, e) = ai.as_base_exp()
                    if (e.is_Rational and b.is_Integer):
                        term_rads[e.q].append((abs(int(b)) ** e.p))
            if (not term_rads):
                break
            if (common_q is None):
                common_q = set(term_rads.keys())
            else:
                common_q = (common_q & set(term_rads.keys()))
                if (not common_q):
                    break
            rads.append(term_rads)
        else:
            for r in rads:
                for q in list(r.keys()):
                    if (q not in common_q):
                        r.pop(q)
                for q in r:
                    r[q] = prod(r[q])
            G = []
            for q in common_q:
                g = reduce(igcd, [r[q] for r in rads], 0)
                if (g != 1):
                    G.append((g ** Rational(1, q)))
            if G:
                G = Mul(*G)
                args = [(ai / G) for ai in args]
                prim = (G * prim.func(*args))
    return (con, prim)
