(a, b, m)
return sols
Solves `ax^2 + by^2 = m` where `\gcd(a, b) = 1 = gcd(a, m)` and `a, b > 0`.

    Uses the algorithm due to Cornacchia. The method only finds primitive
    solutions, i.e. ones with `\gcd(x, y) = 1`. So this method can't be used to
    find the solutions of `x^2 + y^2 = 20` since the only solution to former is
    `(x,y) = (4, 2)` and it is not primitive. When ` a = b = 1`, only the
    solutions with `x \geq y` are found. For more details, see the References.

    Examples
    ========

    >>> from sympy.solvers.diophantine import cornacchia
    >>> cornacchia(2, 3, 35) # equation 2x**2 + 3y**2 = 35
    set([(2, 3), (4, 1)])
    >>> cornacchia(1, 1, 25) # equation x**2 + y**2 = 25
    set([(4, 3)])

    References
    ===========

    .. [1] A. Nitaj, "L'algorithme de Cornacchia"
    .. [2] Solving the diophantine equation ax**2 + by**2 = m by Cornacchia's
        method, [online], Available:
        http://www.numbertheory.org/php/cornacchia.html
Solves `ax^2 + by^2 = m` where `\gcd(a, b) = 1 = gcd(a, m)` and `a, b > 0`.
Solves ax^2 + by^2 = m where \ gcd ( a b ) = 1 = gcd ( a m ) and a b > 0 .
def cornacchia(a, b, m):
    """
    Solves `ax^2 + by^2 = m` where `\gcd(a, b) = 1 = gcd(a, m)` and `a, b > 0`.

    Uses the algorithm due to Cornacchia. The method only finds primitive
    solutions, i.e. ones with `\gcd(x, y) = 1`. So this method can't be used to
    find the solutions of `x^2 + y^2 = 20` since the only solution to former is
    `(x,y) = (4, 2)` and it is not primitive. When ` a = b = 1`, only the
    solutions with `x \geq y` are found. For more details, see the References.

    Examples
    ========

    >>> from sympy.solvers.diophantine import cornacchia
    >>> cornacchia(2, 3, 35) # equation 2x**2 + 3y**2 = 35
    set([(2, 3), (4, 1)])
    >>> cornacchia(1, 1, 25) # equation x**2 + y**2 = 25
    set([(4, 3)])

    References
    ===========

    .. [1] A. Nitaj, "L'algorithme de Cornacchia"
    .. [2] Solving the diophantine equation ax**2 + by**2 = m by Cornacchia's
        method, [online], Available:
        http://www.numbertheory.org/php/cornacchia.html
    """
    sols = set([])

    a1 = igcdex(a, m)[0]
    v = sqrt_mod(-b*a1, m, True)

    if v is None:
        return None

    if not isinstance(v, list):
        v = [v]

    for t in v:
        if t < m // 2:
            continue

        u, r = t, m

        while True:
            u, r = r, u % r
            if a*r**2 < m:
                break

        m1 = m - a*r**2

        if m1 % b == 0:
            m1 = m1 // b
            if isinstance(sqrt(m1), Integer):
                s = sqrt(m1)
                sols.add((int(r), int(s)))

    return sols
def cornacchia ( a , b , m ) : sols = set ( [ ] ) a1 = igcdex ( a , m ) [ 0 ] v = sqrt_mod ( - b * a1 , m , True ) if v is None : return None if not isinstance ( v , list ) : v = [ v ] for t in v : if t < m // 2 : continue u , r = t , m while True : u , r = r , u % r if a * r ** 2 < m : break m1 = m - a * r ** 2 if m1 % b == 0 : m1 = m1 // b if isinstance ( sqrt ( m1 ) , Integer ) : s = sqrt ( m1 ) sols . add ( ( int ( r ) , int ( s ) ) ) return sols