diff --git a/src/sage/quadratic_forms/binary_qf.py b/src/sage/quadratic_forms/binary_qf.py index 0f32bba92ba..d16438bf45b 100755 --- a/src/sage/quadratic_forms/binary_qf.py +++ b/src/sage/quadratic_forms/binary_qf.py @@ -1581,9 +1581,10 @@ def solve_integer(self, n, *, algorithm="general"): sage: Q.solve_integer(773187972) # needs sage.libs.pari (4919, 1337) - If `Q` is of the form `[1,0,c]` as above and `n` is a prime or - four times a prime, Cornacchia's algorithm can be used, which is - typically much faster than the general method:: + If `Q` is of the form `[1,0,c]` as above and `n` is a prime + (or four times a prime whenever `c \equiv 3 \pmod 4`), then + Cornacchia's algorithm can be used, which is typically much + faster than the general method:: sage: Q = BinaryQF([1, 0, 12345]) sage: n = 2^99 + 5273 @@ -1622,16 +1623,30 @@ def solve_integer(self, n, *, algorithm="general"): Also when using the ``"cornacchia"`` algorithm:: sage: # needs sage.libs.pari - sage: abc = [1, 0, randrange(1,10^3)] - sage: Q = BinaryQF(abc) sage: n = random_prime(10^9) - sage: if randrange(2): - ....: n *= 4 - sage: xy1 = Q.solve_integer(n, algorithm='cornacchia') - sage: xy1 is None or Q(*xy1) == n + sage: c = randrange(1, 10^3) + + sage: # needs sage.libs.pari + sage: Q1 = BinaryQF(1, 0, c) + sage: xy = Q1.solve_integer(n, algorithm='cornacchia') + sage: xy is None or Q1(*xy) == n + True + sage: (xy is None) == (Q1.solve_integer(n) is None) + True + + sage: # needs sage.libs.pari + sage: Q3 = BinaryQF(1, 0, 4*c+3) + sage: xy = Q3.solve_integer(n, algorithm='cornacchia') + sage: xy is None or Q3(*xy) == n + True + sage: (xy is None) == (Q3.solve_integer(n) is None) + True + + sage: # needs sage.libs.pari + sage: xy = Q3.solve_integer(4*n, algorithm='cornacchia') + sage: xy is None or Q3(*xy) == 4*n True - sage: xy2 = Q.solve_integer(n) - sage: (xy1 is None) == (xy2 is None) + sage: (xy is None) == (Q3.solve_integer(4*n) is None) True Test for square discriminants specifically (:trac:`33026`)::