Use modular exponentiation by repeated squaring:
Since , multiply the indicated powers to obtain . Only the binary expansion of the exponent determines which squared powers are multiplied.
Pépin's test 2026-10-14
For , Pépin's test says that the Fermat number is a prime number exactly when the displayed modular congruence holds. Modular exponentiation evaluates it by exponentiation by squaring without constructing the enormous ordinary power. The index restriction excludes , where the base itself is divisible by the candidate.[ref]
For a proof outline of sufficiency, any prime factor of a passing candidate gives multiplicative order exactly , a power of two: its half-power is , rather than . Fermat's little theorem forces , so , and hence . Conversely, for a prime candidate, ; quadratic reciprocity and Euler's criterion give the required half-power. At , the check is .
Pollard's p-1 algorithm Created 2026-10-31 Updated 2026-11-05
For an integer to be factored, John Pollard's method chooses an integer coprime to and an exponent divisible by many small prime powers. Compute by modular exponentiation and the Euclidean algorithm. If , it is a proper divisor. If a prime divisor of has , Fermat's little theorem ensures ; success requires some other prime divisor not to divide . Common choices are and . The method exploits a smooth , rather than a small divisor itself.
Quadratic residue Created 2026-09-24 Updated 2026-10-18
For an odd prime , a nonzero congruence class is a quadratic residue when for some integer . Here "quadratic residue" excludes zero: zero is a square of a number, but is neither a quadratic residue nor a quadratic nonresidue under this convention. Some treatments include zero among quadratic residues; the distinction matters when counting them or discussing their subgroup.[ref]
Modulo seven, squaring the six nonzero congruence classes gives
Thus the set of quadratic residues is , and the quadratic nonresidues are . In particular, has exactly the two solutions : and . Modulo eleven the quadratic residues are instead . Two is therefore a quadratic residue modulo seven and a quadratic nonresidue modulo eleven: being a quadratic residue depends on the modulus.
Figure 1.
The square map modulo seven and eleven: two inputs in every nonzero square fiber
. Each pair maps to one quadratic residue. The six nonzero inputs modulo seven give three outputs; the ten modulo eleven give five. The zero fiber is the single input zero, and each quadratic nonresidue has an empty fiber. Details.
Why do the square roots come in pairs? If , the prime number divides , so it divides one factor: or . For nonzero these are distinct, because is an odd prime. Every nonempty nonzero fiber of a function of therefore contains exactly two inputs. Pairing the nonzero congruence classes gives exactly quadratic residues and quadratic nonresidues. Including zero gives different squares, with one rather than two square roots for zero.
The quadratic residues form a subgroup of the multiplicative group of a finite field , with index of a subgroup two. Indeed, one is a square, , and ; the inverses exist because the inputs are nonzero in the prime field. Equivalently, the squaring group homomorphism has kernel of a group homomorphism and image of a function . The apparent loss of a sign in squaring becomes a precise division of the nonzero arithmetic into two equal parts.
This structure turns a search for square roots into a yes-or-no test: Euler's criterion detects quadratic residues through modular exponentiation, and the Legendre symbol records the result as a sign. For a general integer modulus, the modular congruence still makes sense, but the two-root count and the prime field argument need not survive. For example, has four solutions ; the Chinese remainder theorem separates the sign choices modulo three and five.
Residue class Created 2026-09-24 Updated 2026-10-14
For a positive integer modulus , the residue class of an integer is the equivalence class
It contains all integers in the same position of the repeating cycle. For example,
The residue class is this whole infinite collection; its canonical representative is the least nonnegative residue. Euclidean division gives exactly one such representative in , so there are exactly residue classes. When , there is just one, .
Define addition and multiplication of residue classes by
These definitions must give the same answer whichever integers represent the classes. If and modulo , then
Both differences are divisible by , proving that the operations are well-defined. For example, and , since . Replacing nine by gives the same answers with smaller intermediate integers.
With these operations the residue classes form the finite commutative ring , a quotient ring. It need not be a field: although neither factor is the zero class. These zero divisors explain why division requires a unit modulo n. Reducing after each multiplication is especially useful in modular exponentiation, where the unreduced powers can become enormous.
Simultaneous exponentiation by squaring Created 2026-10-24 Updated 2026-11-05
Several powers with the same nonnegative integer exponent can share one exponentiation by squaring loop. Initialize , and . The loop invariants are .
At each step, multiply every by if is an odd integer, then replace every by and by . Indeed,
so all invariants are preserved. The loop variant strictly decreases whenever it is positive. At , the accumulators are exactly the requested powers. For , no iteration is needed and every result is one.
For bases, the method uses multiplications and stored arithmetic values. These are arithmetic-operation counts; exact integer products can grow in bit length. For modular exponentiation, reducing each update modulo its intended integer modulus keeps the stored residues bounded. Sharing the exponent loop does not require mixing the bases' arithmetic types.
Strong pseudoprime Created 2026-09-24 Updated 2026-11-05
Let be an odd integer that is a composite number and write with odd. For a base coprime to , it is a strong pseudoprime when
These are exactly the passing outcomes of the Miller-Rabin primality test for that base. The test computes by modular exponentiation and repeatedly squares it, looking for the permitted value before reaching exponent .
Every strong pseudoprime to a base is a Fermat pseudoprime to that base, by squaring a permitted congruence sufficiently many times. The converse fails. For , one has and , . Neither tested residue is , and the first is not , so base two detects compositeness even though .