Modular arithmetic Created 2026-10-03 Updated 2026-10-13
Modular arithmetic performs addition and multiplication on integers while remembering only their remainders for a fixed positive integer modulus . The relation means that divides : the two integers lie in the same congruence class. For example, , and represent one class modulo . Choosing the least nonnegative residue gives exactly representatives, , even though each congruence class contains infinitely many integers.
A clock supplies a familiar example. Represent the twelve positions by , with at the position usually labelled twelve. Starting at ten and moving seven positions gives
The integer congruence records the final position; it discards the number of complete revolutions. Adding another twelve changes the elapsed count while preserving the position. The picture also shows a single congruence class modulo five spread along the number line.
Figure 1.
Clock addition wraps modulo twelve, while integers separated by five represent one congruence class
. Details.
The useful surprise is that discarding this information still preserves the arithmetic. If and modulo , then and modulo . Thus a large calculation can reduce its intermediate integers after every step. For instance,
Replacing by gives the same answers with smaller intermediate values. The congruence classes with these operations form the quotient ring ; their addition alone forms a cyclic group. This passage from integers to a finite arithmetic system is the setting for modular exponentiation, primality testing and the RSA cryptosystem. [ref]
Multiplicative cancellation needs extra care. Modulo six, , but : multiplication by two has merged distinct congruence classes. Cancelling a factor while retaining the integer modulus is justified when that factor has a modular multiplicative inverse, equivalently when it is coprime to the integer modulus. A linear congruence can consequently have no solutions, one solution class, or several solution classes. The Chinese remainder theorem supplies a complementary operation: splitting a calculation across coprime integer moduli and reconstructing its class modulo their product.
Small remainders can also certify impossibility. A perfect square has residue zero or one modulo four, as checking the four congruence classes shows. Therefore an integer equation has no solution. The converse direction needs care: a permitted residue does not guarantee an integer solution, since but five is not a perfect square. Such local tests provide necessary conditions for Diophantine equations without replacing the full problem.
In Disquisitiones arithmeticae (1801), Carl Friedrich Gauss defines integer congruence in article 1 and adopts the symbol in article 2. Article 12 derives divisibility tests from powers of ten and explains checking arithmetic by its remainders. These passages show a systematic treatment of the same idea; they are not a claim that remainders were first used in 1801. [ref]
Modular exponentiation Created 2026-10-06 Updated 2026-10-14
Modular exponentiation computes the remainder for an integer base , a nonnegative integer exponent , and, here, an integer modulus . It applies exponentiation by squaring while reducing after each multiplication, including each squaring. The result is the unique representative in . There is no requirement that the base be coprime to the modulus when the exponent is nonnegative.[ref]
Take , , and . Initialize ; the remaining digits give
Hence . The final operation multiplies by , since the preceding square has already been reduced. The computation never needs to construct .
In general reduce the base first, . For , initialize and process the remaining binary digits with , followed, for a digit one, by . The loop invariant is
where is the processed prefix value. The congruence is preserved because modular arithmetic respects multiplication: if , then and . Thus changing representatives never changes the final congruence class.
Both factors in every product are less than , so the unreduced product is less than , and the stored result is again less than . The same bounds hold for a gigantic exponent, such as : there are squarings, each on bounded-size residues. For base two, the corresponding ordinary power would have binary digits. The benefit is avoiding the huge ordinary power altogether, rather than constructing it and taking one final remainder. Initial reduction is essential when the supplied base is much larger than the modulus.
For , return under the same empty-product convention as exponentiation by squaring. For , require , find the modular multiplicative inverse , and compute ; the extended Euclidean algorithm can find that inverse. Its cost is separate from the positive-exponent binary powering multiplication count. For example, , while is undefined because and are not coprime.
Modular multiplicative inverse Created 2026-09-24 Updated 2026-10-13
For integers and , a modular multiplicative inverse is a congruence class satisfying . It exists exactly when . Necessity follows because every common divisor of would divide . Conversely, Bézout's identity gives for coprime integers, making an inverse. This is the basic bridge from greatest common divisor calculations to reversible modular arithmetic.
For example, , so . The modular congruence therefore has the unique solution class . Multiplication by sends all seventeen residue classes to different classes; multiplying by reverses it. The inverse criterion and its algorithmic construction are presented in Ankur Moitra, MIT 18.200, 2024, modular inverses and Euclid's algorithm.
By contrast, has no modular inverse modulo . Its products have only residues . Consequently has no solution, while has five solution classes, . Dividing by a noninvertible residue would discard this distinction. In a prime field , every nonzero residue is invertible; a general integer modulus instead gives a quotient ring that can have zero divisors.
Figure 1.
Multiplication by five is reversible modulo seventeen but collapses classes modulo fifteen
. Details.
Choose a reduced residue system . For a unit modulo n , the bijection on the unit group has inverse . Comparing products before and after this permutation gives
The product is a unit; its modular inverse cancels it, proving Euler's theorem. Merely being nonzero would not justify cancellation.[ref]
In the modulo-twelve example, . The permuted representatives have the same product, while the unreduced products equal . Equating these products modulo twelve exposes the fourth power without calculating it directly. Using all nonzero congruence classes instead would include nonunits, whose product need not permit cancellation.
Multiplicative order Created 2026-09-24 Updated 2026-10-13
For coprime integers with , the multiplicative order is the least positive integer such that
It counts the distinct powers in the cyclic subgroup generated by the congruence class of . Thus it is an order of a group element in the unit group .[ref]
For example, the modular exponentiation , starting at , produces . The first return to one takes three steps, so . Starting at the congruence class three and repeatedly multiplying by two instead gives : these are the other three units modulo seven, outside the cyclic subgroup generated by two.
Figure 1.
Multiplication by two modulo seven has two cycles; its powers follow the cycle through one
. Details.
Euler's theorem guarantees a return to one at exponent , where is Euler's totient function. Thus the multiplicative order exists for every unit.[ref] In fact,
By Lagrange's theorem, the size of the cyclic subgroup divides the size of the unit group, which is Euler's totient function. For two modulo seven, this is ; the multiplicative order need not equal Euler's totient function. If , its multiplicative order is one.
The coprime integers hypothesis is necessary: if , any common divisor of and divides one. For instance, powers of two modulo eight give , with no positive-exponent return to one. This sequence eventually settles, but two has no multiplicative order modulo eight.
Number theory Created 2026-09-24 Updated 2026-10-13
Number theory studies integers, their divisibility, and the patterns created by prime numbers. Its questions often have short statements but rigid answers: which integers divide a given one, when does an equation have integer solutions, and when can arithmetic with congruence classes be reversed? The Euclidean algorithm and modular multiplicative inverses connect these questions through explicit calculations.
For example, and . Their shared prime factors give greatest common divisor . The Euclidean algorithm reaches that answer without finding either complete prime factorization. It also produces , an instance of Bézout's identity. This relation certifies every common divisor at once and solves an associated linear Diophantine equation.
Modular arithmetic retains only remainders, but the lost information can be surprisingly controlled. Multiplication by modulo is a permutation of all residue classes, because has modular inverse . Multiplication by modulo collapses fifteen residue classes to three. Thus an apparently small change in the modulus changes whether a calculation can be reversed. The Chinese remainder theorem explains another kind of compression: remainders modulo coprime integers can be combined into one remainder modulo their product.
Simple restrictions help reveal the structure without telling the whole story. Every prime number greater than three is congruent to or modulo : the other four residue classes force divisibility by or . The converse fails because and lie in those classes but are composite numbers. Necessary conditions are useful filters, not substitutes for primality testing.
The subject's appeal lies partly in this tension: prime factorization gives a clean description of every positive integer, while identifying factors and predicting their distribution lead to substantial further questions. Analytic number theory uses tools from analysis to study global patterns, and algebraic number theory extends arithmetic into number fields. Applications include cryptography and error-correcting codes; MIT's discrete applied mathematics course develops modular structures for both purposes. [ref]
Euclid's Elements already gives a greatest-common-measure construction in Book VII, Proposition 2, and the argument that a finite list cannot exhaust the prime numbers in Book IX, Proposition 20. These are documented ancient treatments, rather than evidence that all of number theory began with one author. [ref] [ref]
Order as the exact period of modular exponentiation Created 2026-09-24 Updated 2026-10-14
Let be coprime integers with , and let be their multiplicative order. For integers ,
Negative exponents mean powers of the modular inverse of . Thus periodic modular exponentiation has smallest positive period , and are distinct congruence classes.[ref]
This lets a huge modular exponentiation reuse a short list: reduce its exponent modulo the multiplicative order, then look up the corresponding power. For example, gives , while gives . When the multiplicative order is unknown, Euler's theorem permits reduction modulo Euler's totient function, though that period may be longer. Repeated squaring remains useful when computing either the unreduced or the reduced power.
For a proof outline, multiply by the modular inverse of , leaving . Apply Euclidean division to write with . Then ; minimality of the multiplicative order forces . The reverse implication follows from . The coprime integers hypothesis enables cancellation: modulo eight, , but this repetition supplies no multiplicative order for two.
P-adic number Created 2026-10-03 Updated 2026-10-14
For a prime number , a p-adic number is an element of the field obtained by completing the rational numbers for the metric . Here is the p-adic absolute value. The Cauchy-sequence construction of a metric completion supplies limits for every Cauchy sequence, and addition, multiplication, and the p-adic absolute value extend to this complete metric space. The rational numbers form a dense subset. [ref]
For a concrete example with , consider the partial sums of a geometric series:
The first values have distances from in the 2-adic absolute value. Consequently
This is a statement about convergence in a metric space with the 2-adic absolute value. In the ordinary real number absolute value, the same partial sums grow without bound. Choosing a metric changes which approximation errors shrink.
More generally every nonzero P-adic number has a unique digit expansion
Only finitely many negative powers occur, while positive powers can continue indefinitely. Written with the highest powers on the left, the digits extend infinitely to the left; for example the P-adic number at is written . The p-adic integers are exactly the elements with , whose digit expansions use only nonnegative powers. [ref]
The construction can be understood through modular arithmetic. Successively choose the low-order digits to agree modulo , , and higher powers. After fixing digits below , the remaining error has p-adic absolute value at most ; the partial sums form a Cauchy sequence, so completeness supplies a limit. If two expansions first differ at position , their difference has P-adic valuation , proving uniqueness. This turns compatible finite congruence classes into one exact number. In particular, Hensel's lemma upgrades suitable approximate roots of a polynomial modulo powers of into roots in the p-adic integers.
Quadratic reciprocity Created 2026-09-24 Updated 2026-10-13
Quadratic reciprocity compares two questions: is the prime number a quadratic residue modulo , and is a quadratic residue modulo ? Let be distinct odd primes. In terms of the Legendre symbol,
The two Legendre symbols have opposite signs exactly when both primes are modulo ; otherwise they are equal. Their values are nonzero because the primes are distinct. Equal signs can mean two quadratic residues or two quadratic nonresidues: reciprocity compares the answers rather than declaring either answer positive.[ref]
For a direct computation, the nonzero quadratic residues modulo are respectively , , and . Squaring just suffices because and have the same square modulo an odd prime .
The pair has a sign flip, whereas has two negative signs. These small quadratic residue tables make the distinction tangible.
Figure 1.
Small prime square-residue tables distinguish opposite and equal Legendre symbol signs
. Each row uses half the nonzero inputs; the missing entries are unnecessary. The comparisons and are exact finite examples of quadratic reciprocity, not evidence by themselves for every prime pair. Details.
The first supplementary law for quadratic reciprocity handles numerator , and the second supplementary law for quadratic reciprocity handles numerator :
For an odd prime , is a quadratic residue exactly when , while is a quadratic residue exactly when . The remaining odd congruence classes modulo , namely , make a quadratic nonresidue. These laws fill the cases excluded from swapping distinct odd primes.[ref]
Ultrametric space Created 2026-09-24 Updated 2026-09-24
An ultrametric space is a metric space satisfying the ultrametric inequality. Its open balls are clopen, and any two balls are either disjoint or one contains the other.