Lecture 8 - Integer Properties (Part 2)

Modular Arithmetic

  • Definition: Modular arithmetic (mod n) is a system of arithmetic for integers where numbers "wrap around" when reaching a certain value n, where n \ge 1.

  • The value n is called the modulus.

  • Example: A 12-hour clock operates with a modulus of 12. All time values reset after reaching 12.

    • If the current time is 3, 14 hours later is 5, calculated as (3+14) \mod 12 = 17 \mod 12 = 5.

  • Applications: Modular arithmetic is utilized in various fields:

    • Cryptographic algorithms

    • Hash functions

    • Generating pseudo-random numbers

Congruence

  • Definition: Let a and b be integers, and let n be a positive integer. a is congruent to b modulo n (denoted by a \equiv b \pmod n) if and only if a \mod n = b \mod n.

  • Theorem: Let a and b be integers, and let n be a positive integer. a \equiv b \pmod n if and only if n divides (a-b) (i.e., n | (a-b)).

  • Example: Which of the following numbers are congruent to 3 \mod 11?

    • Numbers: -8, 11, 58, 113

    • -8 \mod 11 = 3 (since -8 = (-1) \cdot 11 + 3) - Yes

    • 11 \mod 11 = 0 - No

    • 58 \mod 11 = 3 (since 58 = 5 \cdot 11 + 3) - Yes

    • 113 \mod 11 = 3 (since 113 = 10 \cdot 11 + 3) - Yes

Arithmetic Modulo n

  • Let a and b be integers, and let n be a positive integer.

  • Addition Modulo n: (a+b) \mod n = ((a \mod n) + (b \mod n)) \mod n

  • Multiplication Modulo n: (a \cdot b) \mod n = ((a \mod n) \cdot (b \mod n)) \mod n

  • Examples:

    • Sum: (158 + 219) \mod 5

      • 158 \mod 5 = 3

      • 219 \mod 5 = 4

      • ((158 \mod 5) + (219 \mod 5)) \mod 5 = (3 + 4) \mod 5 = 7 \mod 5 = 2

    • Product: (158 \cdot 219) \mod 5

      • ((158 \mod 5) \cdot (219 \mod 5)) \mod 5 = (3 \cdot 4) \mod 5 = 12 \mod 5 = 2

    • Mixed Operation: ((13)^{122} + 56) \mod 12

      • 13 \mod 12 = 1

      • 56 \mod 12 = 8

      • ((13 \mod 12)^{122} + (56 \mod 12)) \mod 12 = (1^{122} + 8) \mod 12 = (1 + 8) \mod 12 = 9 \mod 12 = 9

The Fundamental Theorem of Arithmetic

  • Statement: Every positive integer other than 1 can be written uniquely as a prime number or as the product of its prime factors, where the prime factors are written in non-decreasing order.

  • This unique product is called the prime factorization.

  • Process to find prime factorization: To find the prime factorization of a number n, divide n by successive prime numbers, starting with 2, until the quotient is 1.

  • Example: Find the prime factorization of 124.

    • 124 \div 2 = 62

    • 62 \div 2 = 31

    • 31 \div 31 = 1

    • Therefore, 124 = 2 \cdot 2 \cdot 31 = 2^2 \cdot 31.

  • Application: Prime factorization can be used to determine the Least Common Multiple (LCM) and Greatest Common Divisor (GCD) of two positive integers.

Least Common Multiple (LCM) and Greatest Common Divisor (GCD)

  • Let a and b be positive integers.

  • Least Common Multiple (lcm(a, b)): The smallest positive integer that is a multiple of both a and b.

  • Greatest Common Divisor (gcd(a, b)): The largest positive integer that divides both a and b.

  • Relatively Prime: Two integers a and b are considered relatively prime if their greatest common divisor is 1, i.e., gcd(a, b) = 1.

Euclid's Algorithm for GCD

  • Purpose: Computing the prime factorization of large integers is computationally difficult and expensive. Euclid's Algorithm provides a more efficient method to calculate the greatest common divisor of two integers.

  • Algorithm (Pseudocode):
    // Assume a > b gcd(a, b) r = a % b while (r != 0) { a = b b = r r = a % b } return b

  • Example: Use Euclid's Algorithm to compute gcd(81, 60).

    a

    b

    a \pmod b

    81

    60

    81 \pmod {60} = 21

    60

    21

    60 \pmod {21} = 18

    21

    18

    21 \pmod {18} = 3

    18

    3

    18 \pmod 3 = 0

    • The last non-zero remainder is 3. Therefore, gcd(81, 60) = 3.

Finding LCM and GCD using Prime Factorization

  • Given the prime factorizations of two numbers, x and y:

    • To find GCD: Take each common prime factor with the lowest exponent that appears in both factorizations.

    • To find LCM: Take each prime factor (from either number) with the highest exponent.

  • Example: Given the following prime factorizations:

    • 144375 = 3^5 \cdot 5^4 \cdot 7 \cdot 11

    • 205335 = 3^2 \cdot 5^3 \cdot 7 \cdot 11 \cdot 13^2

    • Calculating LCM (taking highest exponents for all distinct prime factors):

      • Prime 3: max(3^5, 3^2) = 3^5

      • Prime 5: max(5^4, 5^3) = 5^4

      • Prime 7: max(7^1, 7^1) = 7^1

      • Prime 11: max(11^1, 11^1) = 11^1

      • Prime 13: max(\text{none}, 13^2) = 13^2

      • Therefore, lcm(144375, 205335) = 3^5 \cdot 5^4 \cdot 7 \cdot 11 \cdot 13^2

    • Calculating GCD (taking lowest exponents for common prime factors):

      • Prime 3: min(3^5, 3^2) = 3^2

      • Prime 5: min(5^4, 5^3) = 5^3

      • Prime 7: min(7^1, 7^1) = 7^1

      • Prime 11: min(11^1, 11^1) = 11^1

      • Prime 13: Not a common factor.

      • Therefore, gcd(144375, 205335) = 3^2 \cdot 5^3 \cdot 7 \cdot 11

Alternative Method for Finding LCM

  • If the greatest common divisor (gcd(a, b)) of two numbers a and b is known, the least common multiple (lcm(a, b)) can be found using the formula:
    lcm(a, b) = \frac{a \cdot b}{gcd(a, b)}

  • Example: To illustrate this formula, if we use the specific GCD value provided in the transcript for these numbers, gcd(144375, 205335) = 3^2 \cdot 5 = 45.

    • Then, lcm(144375, 205335) = \frac{144375 \cdot 205335}{45}.