* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Modular Arithmetic Basics (1) The “floor” function is defined by the
Survey
Document related concepts
Vincent's theorem wikipedia , lookup
Large numbers wikipedia , lookup
Big O notation wikipedia , lookup
List of first-order theories wikipedia , lookup
Abuse of notation wikipedia , lookup
Wiles's proof of Fermat's Last Theorem wikipedia , lookup
Fermat's Last Theorem wikipedia , lookup
Elementary mathematics wikipedia , lookup
Factorization of polynomials over finite fields wikipedia , lookup
Collatz conjecture wikipedia , lookup
List of prime numbers wikipedia , lookup
Transcript
Modular Arithmetic Basics (1) The “floor” function is defined by the formula bxc := ( the greatest integer less than or equal to x). This is also known as “the greatest integer function,” and in old texts is denoted by (whole) brackets. Examples: b3.789c = 3; b−3.789c = −4. (2) The “greatest common divisor,” abbreviated gcd, of a set of integers is, of course, the largest positive integer that divides every integer in the set. Examples: gcd(24, 52) = 4; gcd(54, 42) = 6. (3) The “mod” operator is defined as follows: x mod m := x − m · bx/mc if m 6= 0. For positive integers x and m, x mod m = the remainder in integer division of x by m. Examples: 110 mod 26 = 6; −52 mod 26 = 0. (4) The “mod” relation is defined as follows: a ≡ b (mod m) if and only if a mod m = b mod m. The above definitions make sense even for real numbers. When a, b, m are integers and m > 0, a ≡ b (mod m) if and only if a − b is a multiple of m. Examples: 110 ≡ 6 (mod 26); −80 ≡ 24 (mod 26). (5) Modular arithmetic and algebra behave “as expected” for the operations of addition, subtraction, and multiplication. If a ≡ b (mod m) and c ≡ d (mod m), then a + c ≡ b + d (mod m), a − c ≡ b − d (mod m), and ac ≡ bd (mod m). (6) But division and cancellation are trickier. Here are the cancellation rules. ad ≡ bd (mod m) if and only if a ≡ b (mod m), assuming gcd(d, m) = 1. ad ≡ bd (mod m0 d) if and only if a ≡ b (mod m0 ), assuming d 6= 0. Combined: ad ≡ bd (mod m) if and only if a ≡ b (mod m/ gcd(d, m)). (7) Let a, x, m be integers with m > 0. Let g = gcd(a, m). The number of solutions of ax ≡ b (mod m) in the set {1, 2, . . . , m} is 0 if g does not divide b and is g if g|b, and then if x0 is one solution, then all solutions are given by x = x0 + (m/g)k for k = . . . , −2, −1, 0, 1, 2, 3, . . ., and g of them are in a complete set of residues. (8) Let a, b be integers. Then a|b, read “a divides b,” if and only if b is a multiple, i.e., an integer multiple, of a: b = ka for some integer k. Examples: 7|98; −5|100; but 8 does not divide 26. Graham, Knuth, and Patashnik’s divisibility notation: a\b if and only if a > 0 and a|b. (9) A positive integer p is called prime if it has just two divisors, namely 1 and p. The unending sequence of primes starts thus: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, . . .. The Fundamental Theorem of Arithmetic: There is only one way to write a positive integer as a product of primes in nondecreasing order. Examples: 12 = 2 · 2 · 3, 715 = 5 · 11 · 13. 1 (10) Notation: Write m ⊥ n if gcd(m, n) = 1. This is read as “m is prime to n,” and we say m and n are “relatively prime.” Of course, if m ⊥ n, then n ⊥ m too. (11) The Euler phi function (or totient function) is defined for positive integers n by φ(n) := #{k|0 < k ≤ n, gcd(k, n) = 1}, i.e., φ(n) is the number of positive integers less than or equal to n that are prime to n. n 1 2 3 4 5 6 7 8 9 10 11 12 φ(n) 1 1 2 2 4 2 6 4 6 4 10 4 If p and q are distinct primes, then φ(p) = p − 1 and φ(pq) = (p − 1)(q − 1). (12) Euler’s Theorem: If a ⊥ n, then aφ(n) ≡ 1 (mod n). The special case when n = p, a prime, is known as Fermat’s Little Theorem: If a ⊥ p, then ap−1 ≡ 1 (mod p). (13) The Chinese Remainder Theorem (Sun Tsŭ, c. A.D. 350): If m ⊥ n, then a ≡ b (mod mn) ⇐⇒ a ≡ b (mod m) and a ≡ b (mod n). (14) The extended Euclidean algorithm finds the greatest common divisor g of positive integers a and b (with a > b) and integers s and t such that g = sa + tb. The calculation may be arranged in a tableau. At the start one has q r s t a 1 0 q b 0 1 where q = ba/bc, the integer quotient of a divided by b. Subsequently row j is calculated as follows. rj = rj−2 − qj−1 · rj−1 , sj = sj−2 − qj−1 · sj−1 , tj = tj−2 − qj−1 · tj−1 , qj = brj−1 /rj c. The process ends when the remainder rj = 0. For example, gcd(7469, 2387) = 77 = 8 × 7469 − 25 × 2387: q r s t 7469 1 0 3 2387 0 1 7 308 1 −3 1 231 −7 22 3 77 8 −25 0 The extended Euclidean algorithm may be used to solve ax ≡ b (mod n) when g := gcd(a, n)|b: Calculate g = sa + tn. Then x ≡ sb/g + (n/g)k (mod n) with k = 0, ±1, ±2, . . .. When b = 1, this procedure finds reciprocals mod n.