
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























Outline Zn
Lecture 9
Michael J. Fischer
Department of Computer Science Yale University
February 8, 2010
Outline Zn
(^1) Number theory Modular Arithmetic GCD Modular Multiplication
The two-place relationship ≡n is an equivalence relation. Its equivalence classes are called residue classes modulo n and are denoted by [b]≡n = {a | a ≡ b (mod n)} or simply by [b]. For example, if n = 7, then [10] = {... − 11 , − 4 , 3 , 10 , 17 ,.. .}.
Fact [a] = [b] iff a ≡ b (mod n).
If x ∈ [b], then x is said to be a representative or name of the equivalence class [b]. Obviously, b is a representative of [b]. Thus, [−11], [−4], [3], [10], [17] are all names for the same equivalence class. The canonical or preferred name for the class [b] is the unique integer in [b] ∩ { 0 , 1 ,... , n − 1 }. Thus, the canonical name for [10] is 10 mod 7 = 3.
Let Z denote the set of all integers, positive and negative. Let Zn ⊆ Z contain the non-negative integers less than n, that is,
Zn = { 0 , 1 ,... , n − 1 }.
We now define addition, subtraction, and multiplication operations directly on Zn: a ⊕ b = (a + b) mod n a b = (a − b) mod n a ⊗ b = (a × b) mod n
We will sometimes write +, −, × in place of ⊕, , ⊗, respectively, when it is clear from context that they are to be regarded as operations over Zn rather than over Z.
Definition The greatest common divisor of two integers a and b, written gcd(a, b), is the largest integer d such that d | a and d | b.
gcd(a, b) is always defined unless a = b = 0 since 1 is a divisor of every integer, and the divisor of a non-zero number cannot be larger (in absolute value) than the number itself. Question: Why isn’t gcd(0, 0) well defined?
Fortunately, gcd(a, b) can be computed efficiently without the need to factor a and b using the famous Euclidean algorithm.
Euclid’s algorithm is remarkable, not only because it was discovered a very long time ago, but also because it works without knowing the factorization of a and b.
The Euclidean algorithm relies on several identities satisfied by the gcd function. In the following, assume a > 0 and a ≥ b ≥ 0:
gcd(a, b) = gcd(b, a) (2) gcd(a, 0) = a (3) gcd(a, b) = gcd(a − b, b) (4)
Identity 2 is obvious from the definition of gcd. Identity 3 follows from the fact that every positive integer divides 0. Identity 4 follows from the basic fact relating divides and addition from lecture 8.
Repeatedly applying identity (4) to the pair (a, b) until it can’t be applied any more produces the sequence of pairs
(a, b), (a − b, b), (a − 2 b, b),... , (a − qb, b).
The sequence stops when a − qb < b. How many times you can subtract b from a while remaining non-negative?
The number of times is the quotient ba/bc. The amout a − qb that is left after q subtractions is just the remainder a mod b. Hence, one can go directly from the pair (a, b) to the pair (a mod b, b), giving the identity
gcd(a, b) = gcd(a mod b, b). (5)
The new algorithm requires at most in O(n) stages, where n is the sum of the lengths of a and b when written in binary notation, and each stage involves at most one remainder computation. The following iterative version eliminates the stack overhead: int gcd(int a, int b) { int aa; while (b > 0) { aa = a; a = b; b = aa % b; } return a; }
Two integers a and b are relatively prime if they have no common prime factors, or equivalently, if gcd(a, b) = 1. Let Z∗ n ⊆ Zn contain those integers that are relatively prime to n, so
Z∗ n = {a ∈ Zn | gcd(a, n) = 1}.
Can compute φ(n) for all n ≥ 1 given the factorization of n.
φ(126) = φ(2) · φ(3^2 ) · φ(7) = (2 − 1) · (3 − 1)(3^2 −^1 ) · (7 − 1) = 1 · 2 · 3 · 6 = 36.
The 36 elements of Z∗ 126 are: 1, 5, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41, 43, 47, 53, 55, 59, 61, 65, 67, 71, 73, 79, 83, 85, 89, 95, 97, 101, 103, 107, 109, 113, 115, 121, 125.
Here is an explicit formula for φ(n). Theorem Write n in factored form, so n = pe 11 · · · pe kk , where p 1 ,... , pk are distinct primes and e 1 ,... , ek are positive integers.a^ Then
φ(n) = (p 1 − 1) · pe 11 −^1 · · · (pk − 1) · pe kk −^1. aBy the fundamental theorem of arithmetic, every integer can be written uniquely in this way up to the ordering of the factors.
When p is prime, we have simply φ(p) = (p − 1), so for the product of two distinct primes, φ(pq) = (p − 1)(q − 1).