ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Discrete Structures
    GE-167
    Progress0 / 67 topics
    Topics
    1. Mathematical Reasoning: Propositional and Predicate Logic2. Propositional Logic: Logical Operators3. Translations Between Symbolic Expressions and Formal English Expression4. Logical Equivalences5. Predicate Logic: Quantifiers6. Nested Quantification7. Equivalences in Predicate Logic8. Translations Between Symbolic Forms and Formal English9. Rules of Inference: Proof Methods and Strategies10. Direct Proof11. Proof by Contraposition12. Proof by Induction13. Proof by Implication14. Existence Proof15. Uniqueness Proofs16. Trivial Proofs17. Vacuous Proofs18. Sets: Notations and Set Operations19. Venn Diagrams20. Countable and Uncountable Sets21. Relations: Equivalence Relations and Partitions22. Partial Orderings23. Recurrence Relations24. Functions: Injective, Surjective, Bijective25. Special Types of Functions26. Function Composition27. Inverse Functions28. Recursive Functions29. Compositions30. Number Theory: Sequences and Series31. Counting: Inclusion and Exclusion Principle32. Pigeonhole Principle33. Permutations and Combinations34. Integers and Divisibility: Division Theorem35. Modular Arithmetic36. LCM and GCD37. Euclidean and Extended Euclidean Method38. Finding Solutions to Congruence39. Primes: Fundamental Theorem of Arithmetic40. Characterizations of Primes41. Mersenne Primes42. Induction: Weak Induction43. Strong Induction44. Recursion and Recurrences: Formulation of Recurrences45. Closed Formulas46. Counting: Product Rule and Sum Rule47. Principle of Inclusion-Exclusion48. Binomial Coefficients49. Pascal's Identity and Pascal’s Triangle50. Binomial Theorem51. Relations: Reflexive, Symmetric, Transitive, and Antisymmetric52. Equivalence Relations and Equivalence Classes53. Partial Orders54. Graph Theory: Terminologies55. Elements of Graph Theory56. Planar Graphs57. Graph Coloring58. Euler Graph59. Hamiltonian Path60. Rooted Trees61. Graph Traversals62. Handshaking Lemma and Corollary63. Special Families of Graphs64. Graph Isomorphism65. Planarity in Graphs66. Eulerian and Hamiltonian Graphs67. Trees in Graph Theory
    GE-167›Modular Arithmetic
    Discrete StructuresTopic 35 of 67

    Modular Arithmetic

    11 minread
    1,903words
    Intermediatelevel

    Modular Arithmetic

    Modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value, known as the modulus. It is often described as clock arithmetic because it behaves similarly to how a clock resets after reaching 12 hours. Modular arithmetic is essential in many areas of mathematics, computer science, cryptography, and number theory.

    1. The Basics of Modular Arithmetic

    In modular arithmetic, we are primarily concerned with remainders when dividing numbers by a fixed modulus. The notation used is:

    a≡b(modm)a \equiv b \pmod{m}a≡b(modm)

    This means that when aaa is divided by mmm, the remainder is the same as when bbb is divided by mmm. In other words, aaa and bbb are congruent modulo mmm.

    Explanation:

    • a≡b(modm)a \equiv b \pmod{m}a≡b(modm) if and only if mmm divides a−ba - ba−b, or equivalently, aaa and bbb leave the same remainder when divided by mmm.

    Mathematically, this means:

    a−b=kmfor some integer ka - b = km \quad \text{for some integer } ka−b=kmfor some integer k

    Where kkk is any integer. This implies aaa and bbb are congruent modulo mmm.

    2. Examples of Modular Arithmetic

    Example 1:

    Let's compute 17mod  517 \mod 517mod5:

    • Divide 17 by 5: 17÷5=317 \div 5 = 317÷5=3 with a remainder of 2.
    • So, 17≡2(mod5)17 \equiv 2 \pmod{5}17≡2(mod5).

    This means that 17 and 2 are congruent modulo 5 because both give the same remainder (2) when divided by 5.

    Example 2:

    Compute 29mod  629 \mod 629mod6:

    • Divide 29 by 6: 29÷6=429 \div 6 = 429÷6=4 with a remainder of 5.
    • So, 29≡5(mod6)29 \equiv 5 \pmod{6}29≡5(mod6).

    This means 29 and 5 are congruent modulo 6 because both have the same remainder (5) when divided by 6.

    3. Modular Arithmetic with Negative Numbers

    Modular arithmetic can also be used with negative numbers. The goal is to ensure the remainder is always non-negative and less than the modulus.

    Example 3:

    Compute −17mod  5-17 \mod 5−17mod5:

    • Divide -17 by 5: −17÷5=−4-17 \div 5 = -4−17÷5=−4 (rounding toward negative infinity) with a remainder of 3.
    • So, −17≡3(mod5)-17 \equiv 3 \pmod{5}−17≡3(mod5).

    Here, instead of obtaining a negative remainder, we "adjust" the remainder to be positive by adding the modulus. The remainder is 3 because −17+5×4=3-17 + 5 \times 4 = 3−17+5×4=3.

    General Rule for Negative Numbers:

    When dividing a negative number aaa by mmm, we calculate the remainder as follows:

    • If the remainder rrr is negative, add mmm to rrr until the remainder is positive and less than mmm.

    4. Properties of Modular Arithmetic

    Modular arithmetic follows a set of rules that make calculations easier and more efficient, especially when dealing with large numbers.

    Addition:

    a≡b(modm)andc≡d(modm)⇒a+c≡b+d(modm)a \equiv b \pmod{m} \quad \text{and} \quad c \equiv d \pmod{m} \quad \Rightarrow \quad a + c \equiv b + d \pmod{m}a≡b(modm)andc≡d(modm)⇒a+c≡b+d(modm)

    For example:

    • 7≡2(mod5)7 \equiv 2 \pmod{5}7≡2(mod5) and 9≡4(mod5)9 \equiv 4 \pmod{5}9≡4(mod5), so: 7+9≡2+4(mod5)⇒16≡6(mod5)⇒16≡1(mod5)7 + 9 \equiv 2 + 4 \pmod{5} \quad \Rightarrow \quad 16 \equiv 6 \pmod{5} \quad \Rightarrow \quad 16 \equiv 1 \pmod{5}7+9≡2+4(mod5)⇒16≡6(mod5)⇒16≡1(mod5)

    Multiplication:

    a≡b(modm)andc≡d(modm)⇒a×c≡b×d(modm)a \equiv b \pmod{m} \quad \text{and} \quad c \equiv d \pmod{m} \quad \Rightarrow \quad a \times c \equiv b \times d \pmod{m}a≡b(modm)andc≡d(modm)⇒a×c≡b×d(modm)

    For example:

    • 7≡2(mod5)7 \equiv 2 \pmod{5}7≡2(mod5) and 9≡4(mod5)9 \equiv 4 \pmod{5}9≡4(mod5), so: 7×9≡2×4(mod5)⇒63≡8(mod5)⇒63≡3(mod5)7 \times 9 \equiv 2 \times 4 \pmod{5} \quad \Rightarrow \quad 63 \equiv 8 \pmod{5} \quad \Rightarrow \quad 63 \equiv 3 \pmod{5}7×9≡2×4(mod5)⇒63≡8(mod5)⇒63≡3(mod5)

    Subtraction:

    a≡b(modm)andc≡d(modm)⇒a−c≡b−d(modm)a \equiv b \pmod{m} \quad \text{and} \quad c \equiv d \pmod{m} \quad \Rightarrow \quad a - c \equiv b - d \pmod{m}a≡b(modm)andc≡d(modm)⇒a−c≡b−d(modm)

    Exponentiation:

    ak≡bk(modm)a^k \equiv b^k \pmod{m}ak≡bk(modm)

    Exponentiation in modular arithmetic allows us to compute large powers efficiently using modular exponentiation algorithms (e.g., exponentiation by squaring).

    Example:

    Compute 34mod  53^4 \mod 534mod5:

    • First calculate 34=813^4 = 8134=81.
    • Then calculate 81mod  581 \mod 581mod5: 81÷5=16 (quotient)with remainder81−5×16=81−80=181 \div 5 = 16 \text{ (quotient)} \quad \text{with remainder} \quad 81 - 5 \times 16 = 81 - 80 = 181÷5=16 (quotient)with remainder81−5×16=81−80=1
    • So, 34≡1(mod5)3^4 \equiv 1 \pmod{5}34≡1(mod5).

    5. Modular Inverses

    In modular arithmetic, we often want to "reverse" operations, especially multiplication. For example, we might want to find the modular inverse of a number aaa modulo mmm, which is a number xxx such that:

    a×x≡1(modm)a \times x \equiv 1 \pmod{m}a×x≡1(modm)

    The modular inverse exists only if aaa and mmm are coprime, meaning their greatest common divisor (gcd) is 1, i.e., gcd⁡(a,m)=1\gcd(a, m) = 1gcd(a,m)=1.

    Example:

    Find the modular inverse of 3 modulo 7:

    • We need to find xxx such that 3×x≡1(mod7)3 \times x \equiv 1 \pmod{7}3×x≡1(mod7).
    • Check different values for xxx:
      • 3×1=33 \times 1 = 33×1=3
      • 3×2=63 \times 2 = 63×2=6
      • 3×3=9≡2(mod7)3 \times 3 = 9 \equiv 2 \pmod{7}3×3=9≡2(mod7)
      • 3×4=12≡5(mod7)3 \times 4 = 12 \equiv 5 \pmod{7}3×4=12≡5(mod7)
      • 3×5=15≡1(mod7)3 \times 5 = 15 \equiv 1 \pmod{7}3×5=15≡1(mod7)

    So, the modular inverse of 3 modulo 7 is 5, because 3×5≡1(mod7)3 \times 5 \equiv 1 \pmod{7}3×5≡1(mod7).

    6. Applications of Modular Arithmetic

    1. Cryptography: Modular arithmetic is crucial in modern cryptography, particularly in algorithms like RSA, which rely on modular exponentiation and modular inverses for secure encryption and decryption.

    2. Computer Science: In computer science, modular arithmetic is often used in hashing algorithms, random number generation, and in the design of error-detection and error-correction codes.

    3. Clock Arithmetic: Modular arithmetic is used to model time in a 24-hour or 12-hour clock system, where the hours "wrap around" after reaching a certain value.

    4. Solving Diophantine Equations: Modular arithmetic is used in number theory to solve equations that involve integers and divisibility, such as linear congruences and systems of congruences.

    5. Pseudo-random Number Generation: Modular arithmetic is used in algorithms that generate random numbers, ensuring that the results cycle through a fixed range.

    6. Computer Graphics: In computer graphics, modular arithmetic helps in operations like color manipulation and tiling, where pixel values may "wrap around" within certain bounds.


    7. Conclusion

    Modular arithmetic is a powerful and essential tool in many areas of mathematics, cryptography, and computer science. It allows for efficient computations by focusing on remainders, reducing the size of numbers involved in operations. By understanding modular addition, subtraction, multiplication, exponentiation, and inverses, you can solve a variety of problems that involve large numbers and periodic structures, including encryption, hashing, and number-theoretic applications.

    Previous topic 34
    Integers and Divisibility: Division Theorem
    Next topic 36
    LCM and GCD

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time11 min
      Word count1,903
      Code examples0
      DifficultyIntermediate