Integer and Rational Solutions of a Binary Quadratic Equation (2): Quadratic Residue
In this post, we’re interested in finding any or all integer solutions of a binary quadratic equation:
We assume that the equation is non-degenerate in the sense that .
Normalization
We first normalize the problem to simplify its properties.
- Assume . Otherwise, reduce it to .
- Assume is a prime power. Otherwise, write and solve for each and use CRT to combine all results.
- Assume . If , all solutions are .
- Assume does not divide . Otherwise, write where does not divide .
- If is odd, there exists no solution.
- If is even, must be a multiple of , so reduce it to .
After normalization, the problem that we’re interested in is:
For a prime , an integer such that does not divide , find one or all integer such that
We say that is a quadratic residue modulo if has a solution, and a quadratic non-residue modulo otherwise.
The case of
(Solubility) For , is a quadratic residue modulo if and only if .
To find one or all solutions, we first consider the two easy cases:
- If , certainly the case is and all solutions are .
- If :
- If , all solutions are .
- Otherwise, there is no solution.
Now we assume .
(Any solution) Observe that:
So if satisfies , then satisfies . Thus, we can begin with .
(All solutions) Let be any solution to . It is clear that must be odd. Consider and . The sum is , so only one of them is even. The product is , thus one of them is 0 modulo . Thus, the set of all solutions is:
The case of an odd prime
(Solubility) The solubility is often determined by the Jacobi symbol, which is the generalization of the Legendre symbol: For an odd prime , is a quadratic residue modulo if and only if
where is the Legendre symbol.
Note that this does not apply to (e.g., ) or general composite numbers (e.g., ).
(Modulo a prime ()) There exist well-known algorithms for finding a solution to , e.g., the Tonelli-Shanks algorithm and Cipolla’s algorithm.
(Modulo a prime power ()) Let be any solution to . Tonelli shows that
is a solution to Equation \eqref{eq:quad-residue}.
Alternatively, Cipolla’s algorithm can be extended to find a solution to Equation \eqref{eq:quad-residue} directly: Let be any integer such that is a quadratic non-residue modulo , then
where .
Moreover, it’s also possible to use the identity
to generate a solution from by iterating it for times, but a division modulo takes time so it won’t be faster.
(All solutions) Similarly, let be any solution to . Since , and at most one of and is a multiple of , we conclude that all solutions are
References
- Tonelli-Shanks algorithm
- Cipolla’s algorithm
- [Dickson]: Dickson, L.E., 1919. History of the Theory of Numbers (No. 256). Carnegie Institution of Washington.