Chinese remainder theorem Created 2026-09-24 Updated 2026-10-13
The Chinese remainder theorem says that remainders modulo pairwise coprime positive integers can be specified independently. For pairwise coprime and , every prescribed list determines one congruence class modulo satisfying for all . It determines a class, rather than one unrestricted integer: adding a multiple of preserves every remainder.
For example, combine and . Write from the first condition. The second becomes . Since three has modular inverse two modulo five, , giving . The integers , and all work. The fifteen possibilities modulo fifteen correspond to the fifteen pairs in a three-by-five grid.
Figure 1.
Coprime moduli fill every residue pair; shared factors impose a compatibility condition
. Details.
The theorem also preserves arithmetic: reducing an addition or a multiplication modulo each gives the same tuple as performing that operation on the corresponding congruence classes. In the language of quotient rings, reduction is a ring isomorphism
One large residue is thus an exact encoding of several smaller residues. This is useful for splitting arithmetic into smaller calculations and then reconstructing the result; MIT's modular arithmetic notes develop both the reconstruction and the product representation. [ref] For a concrete multiplication, corresponds to and to modulo . Their componentwise product is , which reconstructs to , agreeing with .
A constructive formula explains the independence. For , put and choose with , using a modular multiplicative inverse. Then is one modulo and zero modulo every other . Therefore
has the desired remainders. A modulus equal to one imposes no restriction and can be omitted. Uniqueness follows because a difference divisible by every is divisible by their product when they are pairwise coprime. This short construction gives a reusable algorithm as well as an existence statement.
The coprime hypothesis explains why every cell in the left grid is attainable. With integer moduli six and eight, a pair must agree modulo their greatest common divisor, two. There are twenty-four compatible pairs, rather than forty-eight arbitrary pairs; each corresponds to a class modulo the least common multiple, twenty-four. The Chinese remainder theorem for noncoprime moduli states the resulting compatibility rule.
Euler's theorem Created 2026-10-03 Updated 2026-10-13
For an integer modulus and an integer with greatest common divisor , Euler's theorem, also called the Fermat-Euler theorem, states
Here Euler's totient function counts the units in the unit group . These congruence classes have modular multiplicative inverses, equivalently their representatives are coprime to . The guaranteed return to one permits exponent reduction for units.[ref]
For a prime number , , recovering Fermat's little theorem in the form when . Multiplying by and separately handling gives for every integer . For a composite number used as the integer modulus, a nonzero congruence class can be a nonunit.
Modulo twelve, the units have representatives , so Euler's totient function gives . Multiplication by five produces
Thus this permutation has two permutation cycles, each of length two. In particular , and the guaranteed return follows. The number of units need not be the length of one permutation cycle. Modulo fifteen, multiplication by seven similarly gives the two permutation cycles and , covering all eight units. The powers of seven follow the permutation cycle containing one; the other permutation cycle shows that these powers do not visit every unit.
Figure 1.
Two unit permutations: multiplication by five modulo twelve and by seven modulo fifteen
. Every arrow multiplies by the indicated unit and reduces modulo the indicated integer modulus. The permutation cycles exhaust each reduced residue system. The permutation cycle containing one records the powers of the multiplier; its length is the multiplier's multiplicative order, which can be smaller than Euler's totient function. Details.
There is a stronger obstruction for a nonunit than just an occasional failed calculation. If a positive integer divides both and , then for every , so cannot be congruent to one modulo . For example, and , rather than one. Such a base has no multiplicative order modulo that integer modulus.[ref]
Euler totient function Created 2026-09-24 Updated 2026-10-13
Euler's totient function is the arithmetic function
It counts the congruence classes modulo represented by integers coprime to . In particular, , since . For , the coprime integers among are , so ; they form a reduced residue system. [ref]
Counting these congruence classes is useful because they are exactly the classes with modular multiplicative inverses. Their number supplies the exponent in Euler theorem. Möbius inversion gives the product formula
where runs over distinct prime factors of . Thus for prime powers with , and . The product for is an empty product, so it gives the same convention .
For a unit modulo n and a nonnegative integer , division with remainder writes with . Euler's theorem then gives
This replaces a potentially enormous exponent by a small remainder. The exponent itself is reduced modulo Euler's totient function, while the powers are reduced modulo : these are different integer moduli.
For a worked modulo-fifteen calculation, seven is coprime to fifteen and . Therefore
Use exponentiation by squaring on the remaining exponent , reducing after each multiplication:
Thus . Modular exponentiation supplies the computation; Euler's theorem supplies the optional shortening of its exponent. Exponentiation by squaring also works for nonunit bases, without using this shortening.
The guaranteed exponent is a common return exponent and an upper bound on the shortest period; it need not be that period. The multiplicative order is the least positive return exponent for the chosen unit. The Carmichael function is the least positive return exponent that works for every unit. Their precise relation is
Either smaller return exponent can replace in exponent reduction for units. Modulo fifteen, , so gives immediately. For base four the multiplicative order is only two, smaller even than . A return at exponent eight alone does not prove that the multiplicative order is eight.[ref]
Figure 1.
Actual power periods, Carmichael function exponents and Euler return exponents
. Each row lists powers from exponent zero through eight. Highlighted first returns identify multiplicative orders; the accompanying labels distinguish a chosen base's shortest period, the common exponent for all units, and Euler's totient function. Powers of the nonunit three modulo fifteen repeat after an initial term but never return to one at a positive exponent. The final calculation compares reduction of modulo eight and modulo four. Details.
If the reduced exponent is zero, the rule gives , and still requires a unit. Applying it to the nonunit three would falsely predict ; the actual residue is six. For negative exponents, first interpret the power using a modular multiplicative inverse, as in modular exponentiation.
Fermat little theorem Created 2026-09-24 Updated 2026-10-14
For a prime number and an integer not divisible by , Fermat's little theorem states the modular congruence
Equivalently, for every integer , including and multiples of ,
The first formulation follows from the second by multiplying by a modular multiplicative inverse of . Conversely, multiply the first by when ; when , both sides of the second are zero modulo . The divisibility condition in the first formulation is essential.[ref]
For , , so and . Also , while : a zero residue class cannot satisfy the first formulation. It does satisfy . A failure at a zero residue class therefore says nothing against a candidate's being a prime number.
The prime number is included. Its only nonzero residue class is one: every odd integer satisfies . Every integer also satisfies , because is even. Testing the first formulation with an even integer would violate its hypothesis.
The useful surprise is that every nonzero residue class returns to one at the same exponent , although its shortest return can be earlier. This gives exponent reduction for units: for a nonnegative integer , when . It also computes a modular multiplicative inverse as modulo , including . Repeated squaring makes these modular exponentiations practical.
In group theory, the nonzero residue classes form the multiplicative group of integers modulo n with , of group order . Lagrange's theorem says that the multiplicative order of divides , giving the guaranteed return. Euler's theorem extends this to a general integer modulus , using the units and Euler's totient function ; the Carmichael function gives the least common return exponent for all units. A nonzero residue class modulo a composite number need not be a unit.
Leonhard Euler's paper presented in 1732 and published in 1738 states a historical formulation: Theorem 1 says that powers with exponent leave zero or one upon division by a prime number . The preceding discussion states the difference-of-powers version and explicitly says that he does not have its proof.[ref]
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.
For an odd integer , a nontrivial square root of unity modulo is a residue with and . Then both and are proper divisors. For , works: , , and .
A congruence of squares with converts to this form by , using a modular multiplicative inverse. In the example, , so . It yields and . Nontriviality requires mixed sign choices across prime factors, which an odd prime number modulus cannot provide.
For a prime number and , multiplication by gives a permutation of the nonzero residue classes. For modulo seven, the representatives map to : the same collection in a different order. Repeating this permutation from one visits all six representatives before returning.
Figure 1.
Multiplication by three modulo seven permutes all six nonzero residue classes
. The upper arrows show each input and its image. The lower arrows repeatedly apply the same permutation to one, displaying the powers modulo seven. The highlighted final one is the first positive return, at exponent six. Details.
For modulo seven, the permutation cycles are instead and . The powers of two visit only the permutation cycle containing one, so their multiplicative order is three. Both permutation cycles return after three steps; applying the permutation six times still fixes every nonzero residue class. Fermat's little theorem guarantees a return at six, not that every base visits every nonzero residue class.
Figure 2.
Multiplication by two modulo seven gives two permutation cycles of length three
. Every arrow multiplies by two modulo seven. The left permutation cycle contains one and hence the powers of two. The right permutation cycle contains the other three nonzero residue classes. Their common length three divides . Details.
More generally, every permutation cycle of this map has length equal to the multiplicative order of : starting at a nonzero residue class , a return means , and its modular multiplicative inverse allows cancellation of . Thus the nonzero residue classes split into equal-length permutation cycles, which also explains the divisibility of the multiplicative order into .
The product argument gives a short proof outline. Since multiplication by is a permutation of the nonzero residue classes,
Every factor is a unit, so their product has a modular multiplicative inverse and can be cancelled. This leaves . The whole argument works for , where the product is just one.[ref]
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]
The extended Euclidean algorithm gives
Back-substituting in these equations produces the Bezout identity
Thus one integer solution is . In fact, subtracting this Bezout identity from any other solution and using that and are coprime integers gives all solutions: , , where .
For the modular arithmetic calculation, is a prime number and is coprime to it, so Fermat little theorem gives . Since , and the preceding Bezout identity identifies as the modular multiplicative inverse of , we obtain
Consequently the least positive representative is .
Multiplying the desired representation by turns it into the integer equation
Since and are coprime integers, the necessary modular multiplicative inverses exist. Choose the unique representatives
Then is divisible by both and , hence by their product, because they are coprime. Defining
therefore gives an integer and proves existence. Any other representation, reduced modulo and , must have the same and , since their allowed ranges contain exactly one representative of each residue. The integer equation then forces the same . This proves uniqueness.
For the prime-power fraction decomposition, put and . The distinct prime-power factors are pairwise coprime, and has a modular multiplicative inverse modulo . Define
Every term with is divisible by , while . Thus is divisible by all the pairwise coprime and therefore by . With , division by yields the required representation. Reducing any such representation modulo each proves uniqueness exactly as above. This is the residue-solving mechanism of the Chinese remainder theorem.
For , the complementary factors are . The required modular inverses give
because , , and . Their numerator sum is . Thus the unique decomposition is
In the RSA cryptosystem, choose distinct large primes , put , and choose coprime to
The decryption exponent is the modular multiplicative inverse
Thus . For a message with , the Fermat-Euler theorem gives
For , . The extended Euclidean algorithm gives
so
Lagrange theorem for polynomial congruences says that a nonzero polynomial of degree over the finite field has at most roots. To prove it, use mathematical induction on . A constant nonzero polynomial has no roots. If , polynomial division in the field gives with . Every root other than is a root of , so the induction hypothesis gives at most roots.
Every nonzero residue class modulo has a unique multiplicative inverse. In the product , pair each class with its inverse. The unpaired classes satisfy , hence . By the theorem these are exactly and , and therefore
This is Wilson theorem.
Now write . By Fermat's little theorem, every nonzero class is a root of
The second factor has degree and hence at most roots. Since their union contains all nonzero classes, has at least roots; Lagrange's theorem gives at most . Thus has exactly solutions.
Prime-power fraction decomposition Created 2026-10-06 Updated 2026-10-13
For a positive integer , every rational number has a unique representation with and . With , the coefficients satisfy . Their existence and uniqueness use modular multiplicative inverses and the Chinese remainder theorem.
Unit modulo n Created 2026-09-29 Updated 2026-10-14
For a positive integer modulus , a residue class is a unit when it has a modular multiplicative inverse: some integer satisfies . Modulo twelve, the units are exactly
In particular, five is its own modular inverse, since . Multiplying all twelve residue classes by five gives a permutation; multiplying the outputs by five recovers the inputs. By contrast, multiplying by six gives only zero and six, with six inputs for each output. It cannot be reversed.
Figure 1.
Multiplication by five permutes all twelve residue classes, whereas multiplication by six merges distinct inputs
. Details.
In general, the exact criterion is
For the forward direction, implies every common divisor of divides one. Conversely, if their greatest common divisor is one, Bézout's identity supplies , so is a modular inverse. The extended Euclidean algorithm computes these coefficients. The units form the unit group under multiplication. [ref]
Multiplicative cancellation while keeping the same integer modulus is valid for a unit modulo n: from , multiply by a modular inverse of to get . A nonunit cannot be cancelled as a general rule. For example, , yet . Thus division by six cannot undo this multiplication; solving a linear congruence instead keeps track of all possible classes.
This distinction marks the boundary between commutative rings and fields. Modulo a prime number , every nonzero residue class is a unit, so is a finite field. Modulo twelve it is a commutative ring with zero divisors, and is not a field. For , the sole class satisfies and is a unit; this one-element zero ring is not a field. [ref]
Wilson's theorem 2026-10-14
For an integer , Wilson's theorem characterizes prime numbers by a factorial:
The right side is an integer congruence, so the least nonnegative remainder is . For example, certifies that five is a prime number, whereas rules out six. [ref]
Figure 1.
Factorial residues distinguish primes from composites, with inverse pairs explaining the prime case
. Details.
For an odd prime number , each nonzero congruence class has a unique modular multiplicative inverse. Pair each class with its inverse: each distinct pair contributes one. A class is its own inverse exactly when ; since , Euclid's lemma leaves only . Their product is . The prime number two needs a separate check: . Conversely, a proper divisor divides both and , so the displayed integer congruence would force , a contradiction. [ref]
The composite numbers have an even sharper pattern: for every composite number , but . To check the zero claim, write with . If , both occur as different factors in the factorial. If , the different factors and both occur since , and their product is divisible by . The only excluded case is . Thus four is an exception to the zero pattern, but still fails Wilson's theorem: its required remainder would be three.
This is an exact primality testing criterion, but direct evaluation is expensive: even reducing modulo after every multiplication still takes a number of multiplications proportional to , which grows exponentially with the number of binary digits of . The problem is not merely storing a huge factorial. The more useful role of Wilson's theorem is simplifying factorial expressions in modular arithmetic. For instance, if is a prime number, then gives by a modular multiplicative inverse.