Modular Arithmetic

Definition 1

  • and are congruent modulo or (a congruence) if they leave the same remainder when divided by m (its modulus)
  • if the difference between a and b is a multiple of m or
  • a and b not congruent modulo m, we write

Theorem 2

  • and are int, m is positive int then if and only if .

Theorem 3

  • a and b are congruent modulo int m > there is int k, that

Theorem 4: the congruent modulo of 2 products & sums

  • if , and , then

Corollary 5

  • m is positive int, a and b are int
  • hard parts:
    • -1 (mod 10) = 9, means adding 9 more to its positive get 10
  • how to imagine modulo of negative numbers
    • imagine number line contains only from 0 to 9, and loop back. After 9, we go back to 0. If we start at 0 and move 1 step left (which is -1), we would land on 9

Definition 6: addition and multiplication modulo m

  • is set {0, 1, …, m - 1}.
  • this is arithmetic modulo m

Properties of ordinary addition / multiplication of integers

  • Closure
  • Associativity
  • Commutativity
  • Identity element
  • Additive inverses

Note on modular arithmetic

  • a set with both mod addition or multiplication is commutative ring

Application of of Modular Arithmetic - Hashing

  • hashing:
  • Pseudorandom sequences: use the linear congruential generator (LCG) to generate
    • choose 4 int: modulus m, multiplier a, increment c, seed , , ,