Which Remainders Can Be Squares?
Section titled “Which Remainders Can Be Squares?”An integer is a quadratic residue modulo if has a solution. Some conventions reserve the term for nonzero residues, so we will explicitly say “nonzero quadratic residue” when needed.
Listing squares modulo a small integer is often enough to rule out an equation:
| Modulus | Possible square residues |
|---|---|
Because , only about half the inputs need to be checked.
Example. Prove that has no integer solutions.
The right side is three modulo eight, but the possible square residues modulo eight are zero, one, and four. The equation is impossible.
Squares Modulo an Odd Prime
Section titled “Squares Modulo an Odd Prime”For an odd prime , exactly nonzero residue classes are squares. The nonzero inputs pair as and , and no other repetition occurs: if , then , so or .
Euler’s criterion says that for ,
It gives a test without searching for a square root. One justification is that every nonzero square satisfies the first equation by Fermat’s theorem. There are already such roots, the maximum possible for that polynomial; every remaining input has value because its value squared is one.
Example. Determine whether is a square modulo .
Compute by squaring:
Euler’s criterion says that five is a nonresidue. Thus has no solution.
The test determines existence, not the square root itself. If a root is needed, a short residue table can still be the fastest method for a small prime.
When Is Negative One a Square?
Section titled “When Is Negative One a Square?”For an odd prime , the number is a quadratic residue exactly when . Euler’s criterion gives
exactly in that case. Equivalently, a square root of negative one has multiplicative order four, forcing .
Example. An odd prime divides . Prove that .
Since , we have and negative one is a square modulo . The criterion above therefore gives .
Primes That Are Three Modulo Four
Section titled “Primes That Are Three Modulo Four”If is prime and , then divides both and . Otherwise, if , division by would give , which is impossible. Thus , and the original congruence then gives .
Removing the resulting factor of and repeating shows that every prime congruent to three modulo four appears to an even exponent in a nonzero sum of two integer squares.
Example. Decide whether can be written as for integers .
Factor . The prime seven is three modulo four and has odd exponent one. The necessary condition fails, so no representation exists.
Constructing Sums of Two Squares
Section titled “Constructing Sums of Two Squares”The product identity
lets us multiply representations. It is also the modulus identity for .
Fermat’s two-square theorem, also called Fermat’s Christmas theorem, says that a prime is a sum of two integer squares. Together with , the product identity, and the obstruction above, it gives the full criterion:
A positive integer is a sum of two integer squares, allowing zero, exactly when every prime divisor congruent to three modulo four has even exponent. The existence direction for primes is a deeper theorem; the small-modulus obstruction alone does not prove it.
Example. Find two different representations of as a sum of two squares.
Use and . The product identity gives
Changing the sign of the second imaginary component gives another representation:
The Legendre Symbol
Section titled “The Legendre Symbol”For an odd prime , the Legendre symbol packages the quadratic-residue test:
The notation is a symbol, not an ordinary fraction. Its numerator can be reduced modulo the denominator, and it is multiplicative:
For nonzero residues, this follows from Euler’s criterion by multiplying the corresponding powers. Cases involving zero are immediate. Thus a product of two nonresidues is a residue, while multiplying a residue by a nonresidue produces a nonresidue.
Example. Modulo seven, both three and five are nonresidues. Determine whether fifteen is a residue.
Multiplicativity gives . Since fifteen is one modulo seven, this agrees with the direct square . The example illustrates that “nonsquare times nonsquare” behaves differently from ordinary positive integers.
Quadratic Reciprocity and the Supplementary Laws
Section titled “Quadratic Reciprocity and the Supplementary Laws”For distinct odd primes , quadratic reciprocity states
The sign changes exactly when both primes are three modulo four. Otherwise the two symbols are equal. The supplementary laws are
Thus two is a residue exactly when or . These are deeper theorems; their role here is to reduce a residue calculation to smaller primes. They do not find an actual square root automatically.
Example. Determine whether six is a square modulo one hundred one.
Factor the numerator: . Since , the first symbol is negative one.
Because , reciprocity gives . Their product is one, so six is a square modulo 101.
Indeed, , providing an explicit check.
Example. Determine whether seven is a square modulo twenty-nine and find its roots if it is.
Reciprocity has no sign change because twenty-nine is one modulo four:
A short search gives . The two roots are six and negative six, or residues six and twenty-three. A prime modulus gives at most two roots of a nonzero quadratic equation.
Do not apply these prime-denominator tests directly to an arbitrary composite modulus. Solve the congruence modulo its prime powers and combine compatible roots with CRT. A composite-symbol analogue can equal one without guaranteeing that a square root exists.
Gaussian Integers and the Norm
Section titled “Gaussian Integers and the Norm”A Gaussian integer is with integers . Its norm is
The norm is multiplicative because complex moduli multiply. Thus finding a sum-of-two-squares representation is equivalent to finding a Gaussian integer with a prescribed norm.
Gaussian integers admit a Euclidean algorithm. Given with , approximate the real and imaginary parts of by nearest integers to obtain a Gaussian integer . Each coordinate error is at most one-half, so the remainder satisfies unless it is zero.
This norm decrease proves termination just as the ordinary Euclidean algorithm does. It also supplies a Gaussian Bézout identity for the GCD. These facts explain why a square root of negative one modulo a prime can be converted into a sum of two squares.
Example. Use the root to construct a sum-of-two-squares representation of thirteen.
Compute a Gaussian GCD of thirteen and . A convenient division is
The next division is exact:
Thus a Gaussian GCD is , whose norm is thirteen. Hence .
The calculation turns the modular root into a Euclidean remainder with the required norm.
Why a Prime That Is One Modulo Four Is a Sum of Squares
Section titled “Why a Prime That Is One Modulo Four Is a Sum of Squares”Let be prime, and choose with . Such a root exists by the negative-one criterion; Wilson’s theorem also constructs one.
Take a Gaussian GCD . Its norm divides , because divides , so the possible norms are .
The norm cannot be one. Otherwise Gaussian Bézout gives a combination of and equal to one. Multiply it by . Since is divisible by , this would force to divide as a Gaussian integer, which is impossible because its imaginary coefficient is negative one.
The norm cannot be either. In that case has norm one, making an associate of . Then would divide , again impossible from the imaginary coefficient.
Therefore . Writing yields . This proves the prime existence theorem using the Euclidean structure of Gaussian integers, rather than inferring existence from a modular test alone.
Constructing Representations of Composite Numbers
Section titled “Constructing Representations of Composite Numbers”Once the prime-factor criterion passes, multiply representations using the two-square identity. Prime factors congruent to three modulo four have even exponents and can be absorbed into a common integer square. Powers of two use , while primes congruent to one modulo four use their individual representations.
Example. Construct a representation of as a sum of two squares.
Since , use and . One simple representation comes from multiplying the known representation of thirteen by the square twenty-five:
Using a nontrivial representation instead, the product identity gives
Changing the conjugate choice gives . Different Gaussian factorizations can produce distinct integer representations.
The distinction between an existence criterion and a construction matters. Factoring the number proves that a representation exists, while multiplying explicit prime representations produces one. A numerical search may be quicker for small numbers, but the structural method scales and explains the result.
Using Residues as a Filter Rather Than a Final Answer
Section titled “Using Residues as a Filter Rather Than a Final Answer”A congruence solution is necessary for an integer equation, but generally not sufficient. Passing tests modulo three, five, and eight does not prove that a square or sum-of-squares representation exists. It merely eliminates some obstructions.
For instance, an integer can be a square modulo several small moduli and still lie strictly between consecutive integer squares. Combine residue information with bounds, factorization, or valuation arguments before declaring a classification complete.
Likewise, if a prime three modulo four divides a sum of squares, the forced common divisor may invite descent. Divide by its square and repeat until the valuation is exhausted. This proves the even-exponent condition and can turn an equation into an impossibility argument when primitivity is assumed.
Primitive Representations and Forced Common Factors
Section titled “Primitive Representations and Forced Common Factors”A sum-of-two-squares representation is primitive when its two entries are coprime. The ordinary existence criterion allows square factors of primes three modulo four, but such a prime forces a common divisor in every representation.
Example. Find all integer representations of forty-five as a sum of two squares and determine whether any is primitive.
Since three divides and is three modulo four, it divides both variables. Write . The equation becomes .
The only absolute-value pair is one and two. Thus all representations of forty-five have absolute values three and six, with independent signs and either order. There are eight ordered representations, and none is primitive because every pair has common divisor three.
The factorization criterion proves existence because has an even exponent on three. The same prime exponent nevertheless prevents primitivity. These are different questions.
A factor of four also prevents a primitive representation: squares are zero or one modulo four, so a sum divisible by four forces both variables even. Hence a primitive sum of two squares contains no prime three modulo four and has at most one factor of two.
Constructing a Right Triangle with Prime Hypotenuse
Section titled “Constructing a Right Triangle with Prime Hypotenuse”If a prime , the product identity gives
Thus a representation of the prime produces an integer right triangle with hypotenuse . For an odd prime, the two entries are coprime and of opposite parity, so the resulting triangle is primitive.
For example, produces legs five and twelve. This connects the prime residue condition to the existence of primitive right triangles with that prime as hypotenuse.
A prime three modulo four cannot occur as the hypotenuse of a primitive integer right triangle: its square being a sum of two squares would force both legs divisible by that prime. This contradiction is another use of the same residue obstruction.