Fact-checked by Grok 2 weeks ago

Modular arithmetic

Modular arithmetic is a fundamental branch of number theory that deals with integers in a cyclic manner, where equivalence is defined by congruence modulo a positive integer n, known as the modulus, such that two integers a and b are congruent modulo n (written a \equiv b \pmod{n}) if n divides their difference a - b. This system effectively "wraps around" numbers upon reaching multiples of n, allowing computations to be reduced to remainders between 0 and n-1, which partitions the integers into n distinct residue classes. For example, in modulo 12, the hours on a clock illustrate how 13 ≡ 1 and 14 ≡ 2, simplifying arithmetic by ignoring multiples of the modulus. The modern formalism of modular arithmetic was introduced by Carl Friedrich Gauss in his seminal 1801 work Disquisitiones Arithmeticae, where he systematically developed the theory of congruences. Gauss's contributions included key results like the law of quadratic reciprocity, which relates solvability of quadratic congruences across different moduli, laying the groundwork for advanced topics in analytic number theory. Elements of related ideas appeared earlier in ancient Chinese mathematics, such as the Chinese Remainder Theorem in the Sunzi Suanjing (3rd–5th century CE). Key properties of modular arithmetic mirror those of standard integer arithmetic, ensuring it forms a structure for each modulus: is an (reflexive, symmetric, and transitive), and operations like and are compatible with , so if a \equiv b \pmod{n} and c \equiv d \pmod{n}, then a + c \equiv b + d \pmod{n} and ac \equiv bd \pmod{n}. and are well-defined on residue classes, enabling efficient computations, while inverses exist for elements coprime to the modulus, leading to theorems like for primes p: a^p \equiv a \pmod{p}. These properties make modular arithmetic indispensable for solving Diophantine equations and analyzing patterns in integers. Beyond , modular arithmetic underpins diverse applications, including —such as the algorithm, which relies on the difficulty of factoring products of large primes modulo n—and error-correcting codes like Reed-Solomon codes used in and transmission.) In , it facilitates hash functions, pseudorandom number generation, and efficient large-integer arithmetic by reducing operations to bounded remainders, as seen in for secure protocols. Its elegance also drove breakthroughs like Andrew Wiles's proof of , via connections to elliptic curves and modular forms.

Foundations

Congruence relation

In modular arithmetic, two integers a and b are said to be congruent modulo a positive integer m, denoted a \equiv b \pmod{m}, if m divides the difference a - b, that is, there exists an integer k such that a - b = k m. Here, m is called the modulus, and the congruent integers a and b leave the same remainder when divided by m. This relation was first systematically introduced by in his 1801 treatise , where he developed it as a foundational tool for . The modulus m defines a partition of the set of all integers into equivalence classes, known as residue classes, each consisting of all integers congruent to a fixed representative modulo m. Congruence modulo m is an equivalence relation on the integers, satisfying the properties of reflexivity, symmetry, and transitivity.
  • Reflexivity: For any integer a, a \equiv a \pmod{m} because a - a = 0 = 0 \cdot m, so m divides a - a.
  • Symmetry: If a \equiv b \pmod{m}, then m divides a - b, which implies m divides b - a = -(a - b), so b \equiv a \pmod{m}.
  • Transitivity: If a \equiv b \pmod{m} and b \equiv c \pmod{m}, then m divides a - b and m divides b - c, so m divides (a - b) + (b - c) = a - c, hence a \equiv c \pmod{m}.

Examples of congruence

A fundamental illustration of the congruence relation arises from the condition that two integers a and b are modulo m if m divides a - b. Consider the integers 17 and 5 with 12. Their difference is $17 - 5 = 12, which is divisible by 12, so $17 \equiv 5 \pmod{12}. This means 17 and 5 occupy the same position in the cyclic structure of residues modulo 12. A practical everyday example is clock arithmetic, which operates modulo 12. Adding 2 hours to 12 o'clock yields 2 o'clock, since $14 \equiv 2 \pmod{12}; the clock "wraps around" after 12, treating 14 as equivalent to 2. Similarly, 11 o'clock plus 1 hour is 12 o'clock, or $12 \equiv [0](/page/0) \pmod{12}, highlighting how time cycles back to the starting point. Even and numbers provide another simple case using modulus 2. All even integers are congruent to modulo 2, as their difference from is even (divisible by 2); for instance, $4 \equiv [0](/page/0) \pmod{2} because $4 - [0](/page/0) = 4 and $2 \mid 4. Odd integers, such as 7, satisfy $7 \equiv 1 \pmod{2} since $7 - 1 = 6 and $2 \mid 6. This partitions the integers into two equivalence classes: evens and s. Visually, congruence modulo m can be represented as a number line that wraps around at every multiple of m, forming a loop or where positions repeat every m units; for modulus 12, the line folds back after 12, 24, and so on, aligning congruent numbers at the same point on the ./04%3A_Number_Theory/4.13%3A__Modular_Arithmetic) A common pitfall is confusing with : while congruent numbers like 17 and 5 12 share properties under by 12, they are distinct integers and not identical. denotes equivalence in a modular , preserving remainders but allowing differences that are multiples of the .

Properties of congruences

Basic properties

The congruence relation preserves the basic arithmetic operations of , , and , allowing computations in modular arithmetic to mirror those in the integers under certain conditions. Specifically, if a \equiv b \pmod{m} and c \equiv d \pmod{m}, then a + c \equiv b + d \pmod{m}. This follows from the definition of : since m divides a - b and m divides c - d, it divides (a + c) - (b + d) = (a - b) + (c - d). Similarly, subtraction is preserved: a - c \equiv b - d \pmod{m}. The proof is analogous to addition, as m divides (a - c) - (b - d) = (a - b) - (c - d), or by noting that subtraction can be expressed as addition with the of c. For multiplication, if a \equiv b \pmod{m} and c \equiv d \pmod{m}, then a \cdot c \equiv b \cdot d \pmod{m}. To see this, expand a \cdot c - b \cdot d = a(c - d) + d(a - b); since m divides both a - b and c - d, and integers are closed under and , m divides the difference. Every a has an modulo m, denoted -a \pmod{m}, such that a + (-a) \equiv 0 \pmod{m}. Explicitly, -a \equiv m - (a \mod m) \pmod{m} if a \not\equiv 0 \pmod{m}, and $0 is its own inverse; this holds because a + (m - a) = m \equiv 0 \pmod{m}. These properties enable straightforward computations. For instance, since $10 \equiv 4 \pmod{6} and $15 \equiv 3 \pmod{6}, it follows that $10 + 15 = 25 \equiv 4 + 3 = 7 \equiv 1 \pmod{6}.

Advanced properties

One advanced property of congruences concerns exponentiation. If a \equiv b \pmod{m} and k is a positive integer, then a^k \equiv b^k \pmod{m}. This result follows from mathematical induction on k, using the basic property that congruences are preserved under multiplication: the base case holds for k=1, and assuming it for k, the inductive step shows a^{k+1} = a^k \cdot a \equiv b^k \cdot b = b^{k+1} \pmod{m}. Linear congruences of the form ax \equiv b \pmod{m}, where a, b, and m > 0 are integers, exhibit sophisticated solvability conditions. The congruence has solutions if and only if \gcd(a, m) divides b; in this case, there are exactly \gcd(a, m) incongruent solutions modulo m. For instance, if \gcd(a, m) = 1, there is a unique solution modulo m, corresponding to the existence of a modular inverse for a modulo m. The Chinese Remainder Theorem provides a key result for systems of congruences with coprime moduli. If m and n are coprime positive integers and a, b are integers, then the system \begin{cases} x \equiv a \pmod{m} \\ x \equiv b \pmod{n} \end{cases} has a unique solution modulo mn. This theorem extends to any finite number of pairwise coprime moduli, enabling the decomposition of problems modulo a product into independent subproblems. Fermat's Little Theorem emerges as a special case of more general exponentiation properties in modular arithmetic. For a prime p and a with \gcd(a, p) = 1, it states that a^{p-1} \equiv 1 \pmod{p}. This can be viewed as a consequence of the structure modulo p, where the order divides p-1. Euler's theorem generalizes Fermat's Little Theorem to composite moduli. If \gcd(a, n) = 1, then a^{\phi(n)} \equiv 1 \pmod{n}, where \phi is , counting the integers up to n that are coprime to n. When n = p is prime, \phi(p) = p-1, recovering exactly. The proof relies on the fact that the units modulo n form a group of order \phi(n), so raising a unit to the \phi(n)-th power yields the identity.

Algebraic structures

Congruence classes

In modular arithmetic, congruence classes arise from the equivalence relation defined by modulo m, where m is a positive , partitioning the set of all \mathbb{Z} into disjoint subsets. The congruence class of an a modulo m, denoted _m, is the set of all b \in \mathbb{Z} such that b \equiv a \pmod{m}, or equivalently, _m = \{ a + k m \mid k \in \mathbb{Z} \}. This concept was first systematically introduced by in his 1801 work , where congruences provided a framework for studying divisibility properties of . These classes form a partition of \mathbb{Z}, meaning they are pairwise disjoint—if _m \neq _m, then _m \cap _m = \emptyset—and their union equals \mathbb{Z}, ensuring every integer belongs to exactly one class. There are precisely m distinct congruence classes modulo m, corresponding to the possible remainders when integers are divided by m. Each individual class is infinite in size, as it contains infinitely many integers differing by multiples of m, yet the finite number of classes captures the periodic structure inherent in modular arithmetic. Any congruent to a modulo m can serve as a representative for _m, but a canonical choice is the least non-negative residue r where $0 \leq r < m, often denoted as the set \{ {{grok:render&&&type=render_inline_citation&&&citation_id=0&&&citation_type=wikipedia}}_m, {{grok:render&&&type=render_inline_citation&&&citation_id=1&&&citation_type=wikipedia}}_m, \dots, [m-1]_m \}. In the context of group theory, these congruence classes can be visualized as cosets of the subgroup m\mathbb{Z} (the multiples of m) in the additive group \mathbb{Z}, where _m = a + m\mathbb{Z}, highlighting their algebraic structure without delving into operations on the classes themselves.

Integers modulo n

The ring of integers modulo n, denoted \mathbb{Z}/n\mathbb{Z} (or \mathbb{Z}_n), is the quotient ring formed by the integers \mathbb{Z} modulo the principal ideal n\mathbb{Z}. Its elements are the congruence classes = \{ k \in \mathbb{Z} \mid k \equiv a \pmod{n} \}, typically represented by the residues $0, 1, \dots, n-1. Addition and multiplication are defined componentwise via the operations on integers, reduced modulo n: specifically, + = [a + b] and \cdot = [a \cdot b]. This structure satisfies the ring axioms: it is an abelian group under addition with identity {{grok:render&&&type=render_inline_citation&&&citation_id=0&&&citation_type=wikipedia}}, multiplication is associative and commutative, distributes over addition, and has a multiplicative identity {{grok:render&&&type=render_inline_citation&&&citation_id=1&&&citation_type=wikipedia}}, making \mathbb{Z}/n\mathbb{Z} a commutative ring with unity. However, if n is composite, \mathbb{Z}/n\mathbb{Z} contains zero divisors—nonzero elements and such that \cdot = {{grok:render&&&type=render_inline_citation&&&citation_id=0&&&citation_type=wikipedia}}—for instance, in \mathbb{Z}/4\mathbb{Z}, {{grok:render&&&type=render_inline_citation&&&citation_id=2&&&citation_type=wikipedia}} \cdot {{grok:render&&&type=render_inline_citation&&&citation_id=2&&&citation_type=wikipedia}} = {{grok:render&&&type=render_inline_citation&&&citation_id=0&&&citation_type=wikipedia}}. The nonzero elements without zero divisors are the units, which are the classes where \gcd(a, n) = 1; these form the multiplicative group (\mathbb{Z}/n\mathbb{Z})^\times under the ring's multiplication. The ideals of \mathbb{Z}/n\mathbb{Z} are principal and correspond to the divisors of n: each ideal is generated by where d divides n, and takes the form d(\mathbb{Z}/n\mathbb{Z}) = \{ \cdot \mid x \in \mathbb{Z}/n\mathbb{Z} \}. When n = p is prime, \mathbb{Z}/p\mathbb{Z} has no zero divisors and every nonzero element is a unit, rendering it a field (also denoted \mathbb{F}_p).

Residue systems

Complete residue systems

A complete residue system modulo m is a set of m integers \{a_0, a_1, \dots, a_{m-1}\} such that the residue classes [a_0], [a_1], \dots, [a_{m-1}] modulo m are all distinct and cover every congruence class in \mathbb{Z}/m\mathbb{Z}. This means that for any integer x, there exists exactly one a_i in the set such that x \equiv a_i \pmod{m}. The standard example of a complete residue system modulo m is the set of least non-negative residues \{0, 1, 2, \dots, m-1\}, where each element represents a unique congruence class. Other sets can be formed by permuting these elements or adding the same multiple of m to each, preserving the distinct classes; for instance, \{km, km+1, \dots, km+(m-1)\} for any integer k is also complete. Properties of complete residue systems include their flexibility in representation: any such system provides an exhaustive enumeration of the congruence classes modulo m, and transformations like adding a fixed multiple of m or rearranging the elements yield equivalent systems. They are particularly useful in computations for indexing all possible residues, such as in iterative algorithms that cycle through every class without repetition. For example, modulo 5, both \{0, 1, 2, 3, 4\} and \{5, 6, 7, 8, 9\} form complete residue systems, as each integer is congruent to exactly one element in the set modulo 5.

Reduced residue systems

A reduced residue system modulo m, where m > 1 is a positive integer, is a set of exactly \phi(m) integers that are pairwise incongruent modulo m and each relatively prime to m, with \phi denoting . This set represents the distinct residue classes modulo m consisting solely of units in the \mathbb{Z}/m\mathbb{Z}. Such a system can be derived from any complete residue system modulo m by excluding elements not coprime to m. The size of a reduced residue system modulo m is precisely \phi(m), which counts the number of integers between 1 and m-1 that are coprime to m. These elements form a complete set of generators for the (\mathbb{Z}/m\mathbb{Z})^*, the group of units modulo m, under modulo m. For instance, when m = 10, \phi(10) = 4, and the set \{1, 3, 7, 9\} serves as a modulo 10, as each element is coprime to 10 and they represent distinct classes. To construct a modulo m, one standard method is to list all integers from 1 to m-1 that share no common prime factors with m, ensuring the count matches \phi(m), which itself can be computed using the inclusion-exclusion principle based on the prime factorization of m. In the special case where m = p is prime, every from 1 to p-1 is coprime to p, so \{1, 2, \dots, p-1\} forms a reduced residue system of size p-1 = \phi(p). This construction highlights the role of reduced residue systems in studying multiplicative properties within modular arithmetic.

Covering systems

A covering system is a finite collection of arithmetic progressions whose union is the set of all integers. Equivalently, it consists of congruences x \equiv a_i \pmod{m_i} with m_i > 1 for each i, such that every integer x satisfies at least one of these congruences. The concept was introduced by in 1950, initially to construct a refuting de Polignac's conjecture by showing that not every odd integer greater than 5 can be expressed as $2^k + p where p is prime (or 1). Erdős's work highlighted connections to (as the union covers the integers with full density 1) and irreducibility (related to minimal such systems where no congruence can be removed without leaving gaps). In 2015, Bob Hough resolved another of Erdős's conjectures on covering systems by proving that there exists a bound such that no covering system with distinct moduli all exceeding this bound (approximately $10^{16}) can exist. Covering systems are classified as distinct if all moduli m_i are unequal, and disjoint (or exact) if the arithmetic progressions have no overlaps, meaning every integer satisfies exactly one congruence. A minimal covering system is one where no proper subset still covers all integers. An example of a distinct covering system with moduli that are mostly powers of 2 is the minimal system \{2^i - 1 \pmod{2^i} : i = 1, \dots, n-1\} \cup \{0 \pmod{2^n - 1}\}, which covers all integers for any n \geq 2. A famous open problem, posed by Erdős, asks whether there exists a disjoint covering system with distinct odd moduli; he offered a $1000 prize for its resolution. This remains unsolved, with partial results showing no such system exists if additional restrictions like square-free moduli are imposed.

Applications

In number theory

Modular arithmetic plays a central role in the study of within . An integer a is a quadratic residue modulo an odd prime p if there exists an integer x such that x^2 \equiv a \pmod{p} and \gcd(a, p) = 1; otherwise, a is a quadratic nonresidue modulo p. The Legendre symbol \left( \frac{a}{p} \right) provides a concise way to determine this status: it equals $1 if a is a quadratic residue modulo p, -1 if a is a quadratic nonresidue modulo p, and $0 if p divides a. Euler's criterion establishes that \left( \frac{a}{p} \right) \equiv a^{(p-1)/2} \pmod{p}, linking the symbol directly to . The law of further connects quadratic residues across different primes. For distinct odd primes p and q, it states that \left( \frac{p}{q} \right) \left( \frac{q}{p} \right) = (-1)^{(p-1)/2 \cdot (q-1)/2}. This result, first proved by in his (1801), allows computation of the \left( \frac{a}{p} \right) by reducing to smaller primes and facilitates the analysis of quadratic forms in . Wilson's theorem provides another key application, characterizing primes via factorials in modular arithmetic. It asserts that for a prime p, (p-1)! \equiv -1 \pmod{p}. This equivalence holds if and only if p is prime, offering a based on modular computation of the . The , proposed by John Wilson and proved by in 1773, underscores the structure of the modulo p. Primitive roots modulo n are generators of the (\mathbb{Z}/n\mathbb{Z})^*, and their existence is tied to specific forms of n. For an odd prime p, there exists a primitive root g modulo p, meaning the order of g in (\mathbb{Z}/p\mathbb{Z})^* is p-1, so powers of g yield all units modulo p. Gauss proved this existence in (1801), and it extends to moduli of the form $2p^k for odd prime p and positive integer k. The number of primitive roots modulo p is \phi(p-1), where \phi is , highlighting the cyclic nature of these groups. Modular arithmetic, particularly through the , aids in determining the solvability of Diophantine equations by checking consistency primes. For instance, the equation x^2 + y^2 = z^2 can be analyzed an odd prime p: solutions exist -1 is a quadratic residue p (i.e., p \equiv 1 \pmod{4}) or if p=2, allowing global solvability to be inferred from local conditions via the theorem. This local-global principle, facilitated by modular reductions, is essential for equations like sums of squares. Dirichlet's theorem on arithmetic progressions demonstrates the density of primes in modular classes. If \gcd(a, m) = 1, then there are infinitely many primes congruent to a modulo m. Proved by in 1837 using analytic methods involving L-functions, this result generalizes Euclid's infinitude of primes and relies on the non-vanishing of certain Dirichlet characters modulo m.

In computing and cryptography

Modular arithmetic plays a central role in applications, particularly in hash functions and pseudorandom number generation, where it enables efficient mapping and sequence production within bounded ranges. The djb2 hash function, developed by , computes a hash value through iterative shifts, additions, and implicit modular reduction via integer overflow, typically modulo $2^{32} or $2^{64}, providing a simple yet effective distribution for hash tables and data integrity checks. This approach leverages the operation to fold large intermediate values back into a fixed-size output space, minimizing collisions in practical implementations. Pseudorandom number generators in often employ linear congruential generators (LCGs), which produce sequences using the recurrence x_{n+1} = (a x_n + c) \mod m, where a, c, and m are chosen parameters, and m defines the for periodicity and uniformity. Introduced by D. H. Lehmer in , LCGs rely on modular multiplication and addition to generate numbers that approximate randomness for simulations, methods, and procedural content in software. The full period of m is achievable under specific conditions on a and c, ensuring the sequence cycles through all residues before repeating. In cryptography, modular arithmetic forms the foundation of public-key systems, enabling secure key exchange and encryption through computationally hard problems in finite fields. The RSA cryptosystem, proposed by Ronald Rivest, Adi Shamir, and Leonard Adleman in 1978, uses modular exponentiation for both encryption and decryption: the ciphertext c is computed as c = m^e \mod n, where m is the plaintext, e is the public exponent, and n = pq is the product of two large primes; decryption recovers m = c^d \mod n using the private exponent d, with security based on the difficulty of factoring n and Euler's theorem ensuring correctness. This modular framework allows asymmetric keys, where the public key (e, n) is shared openly while the private key d remains secret. The Diffie-Hellman key exchange, introduced by and in , facilitates secure generation over insecure channels using in a prime field: one party computes g^a \mod p and shares it, the other computes g^b \mod p, and the shared secret is (g^a)^b \mod p = (g^b)^a \mod p = g^{ab} \mod p, where g is a and p a large prime, relying on the problem for security. Here, g is selected from the p to ensure it generates the . Elliptic curve cryptography (ECC) extends modular arithmetic to elliptic curves over finite fields, typically modulo a large prime p, where point addition and operations are performed to solve the elliptic curve problem. Proposed independently by Neal Koblitz in 1987 and Victor Miller in 1986, ECC achieves equivalent security to larger modulus systems like with shorter keys—for instance, a 256-bit ECC key offers security comparable to a 3072-bit RSA key—due to the curve's group structure defined by Weierstrass equations reduced modulo p. These operations underpin protocols like ECDSA for signatures and ECDH for , with standards from organizations like NIST specifying curves such as P-256 for practical deployment.

In other fields

In music theory, modular arithmetic underpins the analysis of pitch classes in Western twelve-tone equal temperament, where pitches are represented as equivalence classes modulo 12 semitones to account for octave equivalence. This allows transpositions to be computed as additions modulo 12; for instance, shifting a pitch class by 7 semitones corresponds to adding 7 and reducing modulo 12, facilitating the study of intervals and set classes in atonal music. In , modular arithmetic models circadian rhythms by treating time as periodic with a 24-hour cycle, enabling the representation of daily biological oscillations. For example, in simulations of clock models, time variables are adjusted using operations relative to the cycle period (often 24 hours) to simulate phase shifts and light-dark photoperiods, as seen in the Input Signal for SBML models. This approach captures the repetitive nature of and behavioral patterns without unbounded time accumulation. Physics simulations frequently employ modular arithmetic to implement , where particle positions are taken modulo the simulation box dimensions to mimic infinite domains and eliminate . In and lattice-based studies, such as sedimentation of particles in a cubic , coordinates exceeding the box size are wrapped around using modulo the length, ensuring translational invariance and enabling efficient computation of long-range interactions in and . In , seasonal adjustments to data remove predictable yearly cycles by estimating and subtracting periodic components, often indexed 12 for monthly observations to isolate non-seasonal trends like . The U.S. applies methods such as to decompose series into trend-cycle, seasonal, and irregular parts, where seasonal factors are derived from historical patterns repeating every 12 months, aiding accurate forecasting of indicators like and . Modular arithmetic appears in art and design through patterns exhibiting , notably in Penrose tilings, which use aperiodic arrangements of rhombi to create quasiperiodic structures inspired by five-fold symmetry. Constructions of such tilings can incorporate modular operations on angles or vectors to generate non-repeating motifs, as in vector-based methods that apply modulo arithmetic to directions for coloring or subdivision, influencing , , and fractal-inspired visuals.

Computational aspects

Algorithms for modular operations

Modular addition and subtraction are fundamental operations that can be computed directly using the defining property of congruence: for integers a, b, and modulus m > 0, (a + b) \mod m = ((a \mod m) + (b \mod m)) \mod m, and similarly (a - b) \mod m = ((a \mod m) - (b \mod m)) \mod m, where negative results are adjusted by adding m to ensure non-negativity. These formulas handle potential overflow in computations with large integers by reducing operands modulo m beforehand, as described in standard algorithms for multiple-precision arithmetic. For modular multiplication of large integers, the binary method, also known as the Russian peasant algorithm, avoids computing the full product a \times b before reduction. This approach decomposes a into its representation and iteratively doubles b (modulo m) while halving a, adding the current b to the result whenever a is odd; all operations are reduced m to prevent . The algorithm requires O(\log a) additions and shifts, making it efficient for big integers, and has historical roots traceable to around 1800 B.C.E., with modern formalization in computational texts. Modular exponentiation, computing a^b \mod m for large b, employs the square-and-multiply algorithm, which leverages the expansion of b to reduce the number of s. Initialize result as 1; for each bit of b from MSB to LSB, square the current result m and, if the bit is 1, multiply by a m; this performs a squaring for each bit and an extra multiplication for each 1-bit, totaling O(\log b) operations. The dates back over 2,000 years to Babylonian tablet algorithms and was analyzed in detail for computational efficiency in seminumerical contexts. To compute the \gcd(a, m) and, if \gcd(a, m) = 1, the modular of a modulo m via (a x + m y = 1 for integers x, y), the applies successive divisions while back-substituting to find coefficients. Start with the steps: repeatedly replace (a, m) by (m, a \mod m) until remainder 0, yielding \gcd; then reconstruct x and y from the quotients, where the inverse is x \mod m. This extension of Euclid's original algorithm from around 300 B.C.E. enables solving linear Diophantine equations efficiently in O(\log m) steps. For scenarios involving repeated modular multiplications, such as in cryptographic protocols, Montgomery multiplication optimizes by representing numbers in a special "Montgomery form" x R \mod N, where R is a power of the radix coprime to modulus N > 1. The core REDC operation computes z = (T + (T \mod R) N' N) / R \mod N from input T, where N' satisfies R N' \equiv 1 \mod N, yielding z \equiv T R^{-1} \mod N without explicit division by N; converting inputs to Montgomery form allows a sequence of multiplications ending with a final REDC to recover the result. Introduced in 1985, this method reduces trial divisions, making it particularly advantageous for multi-precision arithmetic in fixed-modulus computations.

Complexity of modular computations

Modular addition and subtraction of two integers modulo m, where m has n = \log_2 m bits, can be performed in O(n) time using standard arithmetic operations. For , naive methods achieve O(n^2) bit operations, but optimized algorithms like Karatsuba reduce this to O(n^{1.585}), though in practice for cryptographic sizes, the complexity is often treated as O(n^2) without specialized . Modular exponentiation, computing a^e \mod m, uses the square-and-multiply , which requires O(\log e) modular s, leading to an overall of O(n \cdot \log e) when each multiplication is O(n), or more precisely O(n^2 \log e) in the bit model. This efficiency makes it suitable for large exponents in applications like . The for basic modular operations such as addition, subtraction, and multiplication is O(1) in terms of auxiliary when operands fit in fixed-size words, but for arbitrary large m, big-integer representations require O(n) to store the numbers themselves. Computing the modular inverse of a modulo m, when \gcd(a, m) = 1, via the extended Euclidean algorithm takes O(n) time, as it performs a number of steps proportional to the number of bits in m; the algorithm fails otherwise, returning the gcd instead. Factoring an integer n (i.e., finding its non-trivial factors) is believed to be computationally hard in the classical setting, with no known polynomial-time algorithm for general n, forming the basis for the security of systems like RSA where n is a product of large primes. The best classical algorithms, such as the general number field sieve, run in subexponential time \exp(O((\log n)^{1/3} (\log \log n)^{2/3})). In the quantum setting, factors n in polynomial time, specifically O(n^3 \log n \log \log n) quantum gates, by leveraging quantum within a period-finding subroutine to efficiently compute the of an n. This contrasts sharply with classical bounds, highlighting the potential vulnerability of factorization-based to quantum computation.

References

  1. [1]
    [PDF] Introduction to Modular Arithmetic
    Definition. We define x and y to be congruent modulo n and write x ≡ y mod n if n | (x−y). Definition.
  2. [2]
    [PDF] 8.6 Modular Arithmetic - MIT OpenCourseWare
    1 says that two numbers are congruent iff their remain- ders are equal, so we can understand congruences by working out arithmetic with remainders. And if all ...
  3. [3]
    Modular Arithmetic: Driven by Inherent Beauty and Human Curiosity
    In modular arithmetic, one thinks of the whole numbers arranged around a circle, like the hours on a clock, instead of along an infinite straight line. One ...Missing: definition | Show results with:definition
  4. [4]
    [PDF] Everything You Need to Know About Modular Arithmetic...
    Feb 7, 2006 · Definition Let m > 0 be a positive integer called the modulus. We say that two integers a and b are congruent modulo m if b − a is divisible ...
  5. [5]
  6. [6]
    Disquisitiones arithmeticae : Gauss, Carl Friedrich, 1777-1855
    Aug 11, 2018 · Publication date: 1801. Topics: Number theory. Publisher: Lipsiae : In commiss. apud Gerh. Fleischer, jun. Collection: smithsonian.
  7. [7]
    [PDF] modular arithmetic - keith conrad
    Modular arithmetic lets us carry out algebraic calculations on integers with a system- atic disregard for terms divisible by a certain number (called the ...
  8. [8]
    [PDF] MODULAR ARITHMETIC
    Jun 25, 2024 · Gauss in 1801 and reads-. A≡B(mod n). Once given mod(n), B can be determined from A/n=quotient plus remainder B. So, for instance,-. 17≡ 5(𝑚𝑜𝑑 ...
  9. [9]
    [PDF] Modular Arithmetic
    The motivating example for modular arithmetic is clock arithmetic. What time is it 5 hours after 10 o'clock? The answer 5 + 10 = 15 is fine for military ...
  10. [10]
    Modular Arithmetic -- from Wolfram MathWorld
    . For example, in arithmetic modulo 12 (for which the associated ring is C_(12) ), the allowable numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11. This ...
  11. [11]
    [PDF] Chapter 2, Congruence in Z and modular arithmetic.
    Example. [a] = { b ∈ Z | b ≡ a (mod n) } = { a + kn | k ∈ Z} Modulo 2, there are two classes: [0], the set of even numbers and [1], the set of odd numbers.
  12. [12]
    Modular arithmetic (CS 2800, Spring 2016)
    Definition: given an integer m, two integers a and b are congruent modulo m if m|(a − b). We write a ≡ b (mod m). I will also sometimes say equivalent modulo m.
  13. [13]
    3.1 Congruence
    Carl Friedrich Gauss. Gauss (1777–1855) was an infant prodigy and arguably the greatest mathematician of all time (if such rankings mean anything; certainly he ...
  14. [14]
    5.7: Modular Arithmetic - Mathematics LibreTexts
    Jul 7, 2021 · Modular arithmetic uses only a fixed number of possible results in all its computation. For instance, there are only 12 hours on the face of a clock.
  15. [15]
    Congruences
    We define an addition and a multiplication for residue classes modulo 𝑚 and investi- gate their properties. We assume throughout that the modulus 𝑚 > 1 is fixed ...
  16. [16]
    11.4: Greatest Common Divisors and the Integers Modulo n
    Aug 16, 2021 · Addition modulo n is always commutative and associative; 0 is the identity for + n and every element of Z n has an additive inverse. These ...
  17. [17]
  18. [18]
    Fermat's Little Theorem -- from Wolfram MathWorld
    Fermat's little theorem shows that, if p is prime, there does not exist a base a<p with (a,p)=1 such that a^(p-1)-1 possesses a nonzero residue modulo p.
  19. [19]
    Euler's Totient Theorem -- from Wolfram MathWorld
    A generalization of Fermat's little theorem. Euler published a proof of the following more general theorem in 1736. Let phi(n) denote the totient function.
  20. [20]
    [PDF] EULER'S THEOREM 1. Introduction Fermat's little ... - Keith Conrad
    So the study of decimal expansions might be what led Gauss to discover modular arithmetic in the first place. Page 8. 8. KEITH CONRAD. First generalization ...Missing: statement source
  21. [21]
    7.4: Modular Arithmetic
    ### Summary of Congruence Classes in Modular Arithmetic
  22. [22]
    [PDF] Congruence and Congruence Classes
    Definition 11.11. Let a and n be integers with n > 0. The congruence class of a modulo n, denoted [a], is the set of all integers that are congruent to a ...
  23. [23]
    [PDF] Rings - Columbia Math Department
    Note that, if n > 1, nZ is not a ring with unity. 2. As we saw in Modern Algebra I, Z/nZ is a finite commutative ring with unity for all positive integers n.
  24. [24]
    [PDF] 10 Rings - OU Math
    All but Z are fields (only ±1 are invertible in Z). Example. Z/nZ is a ring. If n is prime, it is also a field. (Z/nZ is a field if and only if n is prime).
  25. [25]
    [PDF] MATH 228: COMMUTATIVE RING THEORY James D. Lewis TABLE ...
    Thus Zn has non-zero zero divisors (which cannot be units), hence is neither a field, nor an integral domain. Ex. Find the units and zero divisors of Z12.
  26. [26]
    [PDF] ADVANCED ALGEBRA I (RINGS AND IDEALS) 1. Chapter VII.1
    Z is a commutative ring with unity 1 and units ±1. Z has no zero divisors. Thus Z is an integral domain. On the other hand, Z/6Z has unity 1 and the units are ...
  27. [27]
    1.20: Zm and Complete Residue Systems - Mathematics LibreTexts
    Aug 17, 2021 · A complete residue system modulo m is sometimes called a complete set of representatives for Z m . Example ...
  28. [28]
    3.2: Residue Systems and Euler's φ-Function - Mathematics LibreTexts
    Jul 7, 2021 · A complete residue system modulo m is a set of integers where every integer is congruent to exactly one of them modulo m. Euler's φ-function ...
  29. [29]
    [PDF] Congruences and Modular Arithmetic - Trinity University
    We say that a is congruent to b modulo n, denoted a ≡ b (mod n), provided n|a − b. Examples. We have: 7 ≡ 22 (mod 5), −4 ≡ 3 (mod 7), 19 ≡ 119.
  30. [30]
    [PDF] Modular Arithmetic
    Modular Arithmetic. Because 0, 1, 2,...,n 1 gives a complete residue system (mod n), it follows that any com- bination of sums, differences and products of ...
  31. [31]
    [PDF] Introduction to Analytic Number Theory
    Definition. By a reduced residue system modulo m we mean any set of ϕ(m) integers, incongruent modulo m, each of which is relatively prime to m. Theorem. If ...
  32. [32]
    [PDF] 3.4 Reduced Residue Systems and Euler's φ Function
    Let S be a complete residue system (mod n). The set S/ consists of those elements in S that are relatively prime to n. The set S/ is called the reduced residue.
  33. [33]
    [PDF] Erd˝os covering systems - People
    Mar 31, 2020 · Erd˝os gave a simple proof that there are only finitely many minimal covering systems of size n. His bound was doubly exponential.Missing: theory | Show results with:theory
  34. [34]
    Covering systems with odd moduli - ScienceDirect.com
    A covering system of the integers is a finite collection of congruences such that every integer satisfies at least one of the congruences in the collection.
  35. [35]
    [PDF] Alex Rice
    Abstract. A covering system is a collection of integer congruences such that every integer satisfies at least one congruence in the collection.
  36. [36]
    [PDF] The Erdos–Selfridge problem with square-free moduli
    One particularly notorious question, due to Erd˝os, asks whether there exist covering systems whose moduli are distinct and all odd. We show that if in addition ...
  37. [37]
    Quadratic Residue -- from Wolfram MathWorld
    If there is an integer 0<x<p such that x^2=q (mod p), ie, the congruence (1) has a solution, then q is said to be a quadratic residue (mod p).Missing: arithmetic | Show results with:arithmetic
  38. [38]
    Legendre Symbol -- from Wolfram MathWorld
    The Legendre symbol is a number theoretic function (a/p) which is defined to be equal to +/-1 depending on whether a is a quadratic residue modulo p.Missing: modular arithmetic
  39. [39]
    Quadratic Reciprocity Theorem -- from Wolfram MathWorld
    The quadratic reciprocity theorem was Gauss's favorite theorem from number theory, and he devised no fewer than eight different proofs of it over his lifetime.
  40. [40]
    Wilson's Theorem -- from Wolfram MathWorld
    This theorem was proposed by John Wilson and published by Waring (1770), although it was previously known to Leibniz. It was proved by Lagrange in 1773.Missing: source | Show results with:source
  41. [41]
    Hash Functions
    djb2. this algorithm (k=33) was first reported by dan bernstein many years ago in comp.lang.c. another version of this algorithm ( ...
  42. [42]
    Random Number Generation contributed by Blair Christian ... - Faculty
    The use of congruential generators goes back at least to Lehmer (1951), and was originally run on a decimal (base 10) computer. ( see this link for more ...
  43. [43]
    [PDF] A Method for Obtaining Digital Signatures and Public-Key ...
    We demonstrate in this paper how to build these capabilities into an electronic mail system. At the heart of our proposal is a new encryption method. This ...Missing: modular | Show results with:modular
  44. [44]
    [PDF] New Directions in Cryptography - Stanford Electrical Engineering
    DIFFIE. AND. HELLMAN: NEW. DIRECTIONS. IN CRYPTOGRAPHY. 653 of possible keys. Though the problem is far too difficult to be laid to rest by such simple methods ...
  45. [45]
    [PDF] Elliptic Curve Cryptosystems - Evervault
    Abstract. We discuss analogs based on elliptic curves over finite fields of public key cryptosystems which use the multiplicative group of a finite field.
  46. [46]
    [PDF] NIST.SP.800-186.pdf
    It also gives cryptographic criteria for the selection of suitable elliptic curves and provides more details on finite field arithmetic and data representation ...Missing: paper | Show results with:paper
  47. [47]
    6.3: Modulo Arithmetic - Humanities LibreTexts
    Jul 15, 2023 · Modular arithmetic is like regular arithmetic, except that the numbers “wrap around” or restart when they reach a certain value, called the modulus.
  48. [48]
    The Input Signal Step Function (ISSF), a Standard Method to ...
    We assume that the time variable t(t ≤ 0) may be reduced to t′ via modular arithmetic and, further, an arbitrary phase may be added so that t′ = (t + φ) modulo ...
  49. [49]
    Periodic sedimentation of three particles in periodic boundary ...
    Aug 30, 2005 · Periodic boundary conditions are widely used in numerical simulation of suspensions. ... Hence the motion z 2 ( t ) modulo L is also periodic.
  50. [50]
    Seasonal Adjustment Methodology at BLS - Bureau of Labor Statistics
    Feb 12, 2025 · The time series are generally run through the seasonal adjustment program once a year to provide the projected factors for the ensuing months ...
  51. [51]
    [PDF] arXiv:2506.07638v1 [math.CO] 9 Jun 2025
    Jun 9, 2025 · Abstract. We present a construction of a family of non-periodic tilings using elementary tools such as modular arithmetic and vector geometry.
  52. [52]
    [PDF] The art of computer programming
    The algorithms discussed in this book deal directly with numbers; yet I ... the processes of arithmetic, after centuries of progress. It discusses ...
  53. [53]
    [PDF] Russian Peasant Multiplication Algorithm, RSA Cryptosystem, and a ...
    This method is called Russian peasant multiplication algorithm because it was first observed in the 19 century by the Western visitors to Russia – where this ...
  54. [54]
    Origin of square-and-multiply algorithm - MathOverflow
    Sep 20, 2012 · This method is indeed over 2000 years old. The history, with references, is discussed by Donald Knuth in Seminumerical Algorithms, volume 2 ...
  55. [55]
    The Euclidean Algorithm and the Extended Euclidean Algorithm
    Aug 14, 2010 · The Euclidean algorithm is an efficient method to compute the greatest common divisor (gcd) of two integers. It was first published in Book VII ...
  56. [56]
    [PDF] Modular Multiplication Without Trial Division Author(s)
    PETER L. MONTGOMERY the algorithms for subtraction, negation, equality/inequality test, multiplication by an integer, and greatest common divisor with N. To ...
  57. [57]
    [PDF] Time Complexities of Multiple-precision Modular Operations and ...
    Analogous to a bitwise modular addition, the time complexity of a non-bitwise modular addition is. 2n (= O(n)) single-precision adding (or subtracting) ...
  58. [58]
    [PDF] Efficient Modular Exponentiation Based on ... - Thomas Plantard
    In this paper, we focus on the variants of the square-and-multiply robust against timing and SPA attacks, by ensuring a regularity of the sequence of ...Missing: original | Show results with:original
  59. [59]
    Big Integer Design - BearSSL
    This page explains the design and implementation of operations on big (modular) integers, used for RSA and generic elliptic curve computations. ... An algorithm ...
  60. [60]
    Modular Inverse - Algorithms for Competitive Programming
    Aug 20, 2023 · Finding the Modular Inverse using Extended Euclidean algorithm¶ ... The exact time complexity of the this recursion is not known. It's is ...Definition · Finding the modular inverse...
  61. [61]
    [PDF] Complexity of Factoring Integers - Purdue Computer Science
    Factoring n (n=pq) is hard for RSA. Known deterministic algorithms have exponential time complexity, though some non-rigorous ones are subexponential.