{
  "id": "modular-arithmetic",
  "title": "Modular Arithmetic",
  "lang": "en",
  "source_lang": "en",
  "summary": "Modular arithmetic studies integer calculations in which numbers differing by a multiple of a fixed modulus are treated as equivalent.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Clock arithmetic",
    "Arithmetic modulo n"
  ],
  "generated_at": "2026-10-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/modular-arithmetic/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/modular-arithmetic/",
      "json": "https://aiwiki.page/zh/modular-arithmetic.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Modular arithmetic is a system of arithmetic in which integers are compared and combined according to their remainders upon division by a fixed positive integer, called the modulus. Numbers differing by a multiple of the modulus are treated as equivalent. This produces “wraparound” calculations rather than an indefinitely increasing number line. Modular arithmetic provides a basic language for number theory and underlies important constructions in cryptography. (cs.cornell.edu)"
    },
    {
      "heading": "Congruence and remainders",
      "text": "For a positive integer \\(n\\), the notation\n\n\\[a\\equiv b\\pmod n\\]\n\nmeans that \\(n\\) divides \\(a-b\\), or equivalently that \\(a-b=kn\\) for some integer \\(k\\). Thus \\(17\\equiv5\\pmod{12}\\), because their difference is \\(12\\). Negative integers also have residues: \\(-1\\equiv11\\pmod{12}\\). The statement describes a relationship between integers, not ordinary equality between them. (cs.cornell.edu)\n\nBy division with remainder, every integer has a unique expression \\(a=qn+r\\), where \\(0\\leq r<n\\). The number \\(r\\) is its least nonnegative residue modulo \\(n\\). Consequently, congruent integers have the same remainder. The expression \\(a\\bmod n\\) usually denotes this particular remainder, whereas “\\(\\pmod n\\)” in a congruence specifies the relation being used. (cs.cornell.edu)\n\nA twelve-hour clock illustrates the idea: advancing five hours from ten gives three, since \\(10+5\\equiv3\\pmod{12}\\). The clock label twelve represents residue zero. This analogy explains wraparound addition, although the mathematical system also supports multiplication and more general algebraic operations. (pi.math.cornell.edu)"
    },
    {
      "heading": "Arithmetic rules",
      "text": "Congruences respect addition, subtraction, and multiplication. If \\(a\\equiv b\\pmod n\\) and \\(c\\equiv d\\pmod n\\), then\n\n\\[a+c\\equiv b+d,\\qquad a-c\\equiv b-d,\\qquad ac\\equiv bd\\pmod n.\\]\n\nIntermediate results may therefore be reduced modulo \\(n\\) without changing the final residue. For example, modulo seven, \\(19\\cdot23\\equiv5\\cdot2\\equiv3\\). Reducing first often makes calculations substantially smaller. (cs.cornell.edu)\n\nRepeated multiplication also gives \\(a^k\\equiv b^k\\pmod n\\) for every nonnegative integer \\(k\\). These rules extend to evaluating any polynomial with integer coefficients. However, exponents cannot generally be reduced modulo the same modulus: \\(2^4\\equiv1\\pmod5\\), whereas \\(2^{4+5}\\equiv2\\pmod5\\). Exponent reduction requires separate conditions and theorems. (cs.cornell.edu)"
    },
    {
      "heading": "Residue classes and algebraic structure",
      "text": "Congruence modulo \\(n\\) is an equivalence relation: it is reflexive, symmetric, and transitive. It partitions the integers into \\(n\\) residue classes. The class containing \\(a\\) is\n\n\\[[a]=a+n\\mathbb Z=\\{a+kn:k\\in\\mathbb Z\\}.\\]\n\nThe collection of classes is denoted \\(\\mathbb Z/n\\mathbb Z\\), also written \\(\\mathbb Z_n\\). Addition and multiplication are defined by \\([a]+[b]=[a+b]\\) and \\([a][b]=[ab]\\); the congruence rules ensure that the definitions do not depend on the chosen representatives. (cs.cornell.edu)\n\nIn abstract algebra, this structure is a commutative ring with identity. Its additive structure is a cyclic group, connecting it with group theory. If \\(n\\) is a prime number, every nonzero class is invertible, so the ring is a field, specifically a finite field with \\(n\\) elements. Composite moduli instead admit nonzero classes whose product is zero: modulo six, \\([2][3]=[0]\\). (cs.cornell.edu)"
    },
    {
      "heading": "Inverses and linear congruences",
      "text": "A modular multiplicative inverse of \\(a\\) is an integer \\(u\\) satisfying \\(au\\equiv1\\pmod n\\). It exists exactly when the greatest common divisor \\(\\gcd(a,n)\\) equals one. The extended Euclidean algorithm finds integers \\(u,v\\) satisfying \\(au+nv=1\\); reducing this identity modulo \\(n\\) gives the inverse. For instance, three has inverse five modulo seven. (math.stanford.edu)\n\nDivision therefore means multiplication by an inverse, not ordinary integer division. Cancellation can fail when the factor is not invertible: \\(2\\cdot1\\equiv2\\cdot4\\pmod6\\), but \\(1\\not\\equiv4\\pmod6\\). More generally, cancelling \\(a\\) changes the modulus to \\(n/\\gcd(a,n)\\). (cs.cornell.edu)\n\nA linear congruence \\(ax\\equiv b\\pmod n\\) has a solution precisely when \\(d=\\gcd(a,n)\\) divides \\(b\\). When solvable, it has exactly \\(d\\) distinct solutions modulo \\(n\\). For example, \\(4x\\equiv2\\pmod6\\) has the two solutions \\(x\\equiv2\\) and \\(x\\equiv5\\). These facts follow by applying the inverse criterion after dividing the coefficients and modulus by \\(d\\). (math.stanford.edu)"
    },
    {
      "heading": "Fundamental theorems",
      "text": "Fermat’s little theorem states that \\(a^p\\equiv a\\pmod p\\) for prime \\(p\\). If \\(p\\) does not divide \\(a\\), this becomes \\(a^{p-1}\\equiv1\\pmod p\\). Euler’s theorem generalizes the latter statement:\n\n\\[a^{\\varphi(n)}\\equiv1\\pmod n \\quad\\text{when }\\gcd(a,n)=1.\\]\n\nHere Euler’s totient function \\(\\varphi(n)\\) counts the integers from one through \\(n\\) that are relatively prime to \\(n\\). (math.stanford.edu)\n\nThe Chinese remainder theorem combines congruences with pairwise coprime moduli. Given \\(x\\equiv a_i\\pmod{n_i}\\), it guarantees one solution class modulo \\(n_1\\cdots n_k\\). Thus \\(x\\equiv2\\pmod3\\) and \\(x\\equiv3\\pmod5\\) together give \\(x\\equiv8\\pmod{15}\\). (math.stanford.edu)"
    },
    {
      "heading": "Historical development and applications",
      "text": "Carl Friedrich Gauss presented a systematic treatment of congruences in Disquisitiones Arithmeticae, published in 1801. Its opening sections address congruences generally, linear congruences, and residues of powers, establishing the framework for subsequent investigations. (e-rara.ch)\n\nIn computer science, modular calculations support hash-table indexing, check digits, and pseudorandom sequences. They also explain decimal divisibility tests: because \\(10\\equiv1\\pmod9\\), an integer is congruent modulo nine to the sum of its digits. (cs.cornell.edu)\n\nThe RSA cryptosystem uses modular exponentiation with a modulus formed from two primes. Its basic mathematical transformation is \\(c=m^e\\bmod n\\), with a related private exponent reversing the transformation. Secure encryption requires additional encoding and padding mechanisms beyond this arithmetic operation. (cs.cornell.edu)"
    }
  ],
  "links": [
    "arithmetic",
    "integer",
    "number-theory",
    "cryptography",
    "polynomial",
    "equivalence-relation",
    "abstract-algebra",
    "ring-mathematics",
    "group-theory",
    "prime-number",
    "field-mathematics",
    "finite-field",
    "modular-multiplicative-inverse",
    "greatest-common-divisor",
    "euclidean-algorithm",
    "fermats-little-theorem",
    "eulers-theorem-number-theory",
    "eulers-totient-function",
    "chinese-remainder-theorem",
    "carl-friedrich-gauss",
    "computer-science",
    "rsa-cryptosystem",
    "modular-exponentiation"
  ],
  "sources": [
    {
      "title": "cs.cornell.edu/courses/cs2800/2017sp/handouts/pass_tseng_discmath.pdf",
      "url": "https://www.cs.cornell.edu/courses/cs2800/2017sp/handouts/pass_tseng_discmath.pdf"
    },
    {
      "title": "cs.cornell.edu/courses/cs2800/2016sp/lectures/lec12-modular.html",
      "url": "https://www.cs.cornell.edu/courses/cs2800/2016sp/lectures/lec12-modular.html"
    },
    {
      "title": "pi.math.cornell.edu/~mec/Summer2008/lundell/lecture2.html",
      "url": "https://pi.math.cornell.edu/~mec/Summer2008/lundell/lecture2.html"
    },
    {
      "title": "cs.cornell.edu/courses/cs2800/2017sp/lectures/lec32-modular.html",
      "url": "https://www.cs.cornell.edu/courses/cs2800/2017sp/lectures/lec32-modular.html"
    },
    {
      "title": "math.stanford.edu/~vakil/putnam04/04putnam2.pdf",
      "url": "https://math.stanford.edu/~vakil/putnam04/04putnam2.pdf"
    },
    {
      "title": "e-rara.ch/zut/content/structure/1254642",
      "url": "https://www.e-rara.ch/zut/content/structure/1254642"
    },
    {
      "title": "cs.cornell.edu/courses/cs5431/2017sp/Lec4-RSA.pdf",
      "url": "https://www.cs.cornell.edu/courses/cs5431/2017sp/Lec4-RSA.pdf"
    }
  ],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}