← LibrarySolving Quadratic CongruencesEngineering · MathematicsLesson 223/385← PrevNext →
ArticlePublished 7 Aug 20262 min readBy Kevin Joginquadratic congruencecompleting the squarediscriminantmodular equation

Euclidean Algorithms and Congruences

Solving Quadratic Congruences

Reducing a general quadratic congruence to a square root extraction, and handling the degenerate cases the reduction assumes away.

Engineering / MathematicsEuclidean Algorithms and Congruences2 min readKV-MATH-0521

A general quadratic congruence reduces to extracting a square root, by exactly the completion of the square used over the reals. The interest lies entirely in the cases where the reduction breaks down.

The reduction

a x^2 + b x + c = 0 (mod p)With a invertible modulo p.

Solving a quadratic congruence modulo an odd prime

  1. NormaliseMultiply through by the inverse of a, obtaining a monic congruence.
  2. Complete the squareSubstitute to remove the linear term; the constant becomes the discriminant divided by four.
  3. Test solvabilityEvaluate the Legendre symbol of the discriminant. If -1, there is no solution.
  4. Extract the rootApply Shanks-Tonelli.
  5. Back-substituteRecover the two solutions.

Degenerate cases

Cases the standard reduction does not cover
ConditionBehaviour
p divides aCongruence is linear, not quadratic; solve directly
p = 2Completion of the square fails; enumerate the two residues
Discriminant zero mod pA single repeated root
Legendre symbol -1No solution

Prime powers

Modulo a prime power, solve first modulo the prime, then lift. The lifting is straightforward when the derivative of the polynomial at the root is invertible — the non-degenerate case. When it is not, several roots may lift to each root or none may, and the case analysis must be done explicitly.

Where this appears

Quadratic congruences arise in quadratic sieve initialisation, where the sieve positions are the roots of a quadratic modulo each factor base prime, and in form reduction when representing an ideal by a binary quadratic form.

Source. Henri Cohen, A Course in Computational Algebraic Number Theory, Springer GTM 138 — 1.4.4. Structural reference unverified: the source file was not available during authoring; chapter and section numbers are taken from the published edition and have not been checked against a physical copy.

Continue learning

Square Roots Modulo a Prime: the Shanks-Tonelli AlgorithmArticle · MathematicsNEXT LESSON →Modular Inversion and Simultaneous InversionArticle · MathematicsLegendre, Jacobi and Kronecker Symbol ComputationArticle · MathematicsFinite Field Element RepresentationArticle · Mathematics