Slides15 Number Theory
Slides15 Number Theory
• Corollary 1
• If a, b, and c are integers, where a != 0, such that a | b
and a | c, then a | mb + nc whenever m and n are
integers.
Divisibility
• Theorem 2 (division algorithm)
• Let a be an integer and d a positive integer. Then there
are unique integers q and r, with 0 ≤ r < |d|, such that
a = dq + r
• a: dividend (số bị chia)
• d: divisor (số chia)
• r: remainder (số dư)
• q = a div d, r = a mod d.
• Example
• What are the quotient and remainder when −11 is
divided by 3?
Modular Arithmetic
• Definition 2 (Congruence - Đồng dư)
• If a and b are integers and m is a positive integer, then a is
congruent to b modulo m if m divides a − b.
if and only if
a mod m = b mod m.
Modular Arithmetic
• Theorem 4
• Let m be a positive integer.
a ≡ b (mod m)
if and only if
• Euclidean algorithm
• Suppose that a and b are positive integers with a ≥ b. Let
r0 = a and r1 = b. When we successively apply the
division algorithm, we obtain:
The Euclidean Algorithm
• Euclidean algorithm
• Suppose that a and b are positive integers with a ≥ b. Let
r0 = a and r1 = b. When we successively apply the
division algorithm, we obtain:
The Euclidean Algorithm
• Example
• Find the greatest common divisor of 414 and 662 using
the Euclidean algorithm.
• Solution
The Euclidean Algorithm
• Example
• Find the greatest common divisor of 414 and 662 using
the Euclidean algorithm.
• Solu+on:
• Successive uses of the division algorithm give:
• 662 = 414·1 + 248
• 414 = 248·1 + 166
• 248 = 166·1 + 82
• 166 = 82 · 2 + 2
• 82 = 2 · 41
• Hence, gcd(414, 662) = 2.
The Euclidean Algorithm
• Euclidean Algorithm
int gcd(int a, int b) {
int r;
while (b != 0) {
r = a % b;
a = b;
b = r;
} int gcd(int a, int b) {
return a; return b == 0 ?
} a : gcd(b, a%b);
}
gcds as Linear Combina0ons
• Bézout’s Theorem
• If a and b are posi.ve integers, then there exist integers
s and t such that gcd(a, b) = sa + tb.
• Defini2on
• If a and b are posi.ve integers, then integers s and t
such that gcd(a, b) = sa + tb are called Bézout
coefficients of a and b.
• The equa.on gcd(a, b) = sa + tb is called Bézout’s
iden.ty.
gcds as Linear Combinations
• Example
• Express gcd(252, 198) = 18 as a linear combina;on of
252 and 198.
• Solu;on
• To show that gcd(252, 198) = 18, the Euclidean
algorithm uses these divisions:
• 252 = 1 · 198 + 54
• 198 = 3 · 54 + 36
• 54 = 1 · 36 + 18
• 36 = 2 · 18.
gcds as Linear Combinations
• Solution
• To show that gcd(252, 198) = 18, the Euclidean
algorithm uses these divisions:
• 252 = 1 · 198 + 54
• 198 = 3 · 54 + 36
• 54 = 1 · 36 + 18
• 36 = 2 · 18
• 18 = 54 - 1.36
= 54 – (198 – 3.54)
= 4.54 – 198
= 4(252 – 1.198) – 198
= 4.252 – 5.198
gcds as Linear Combinations
• Extended Euclidean Algorithm (finding s & t)
• gcd(a, b) = s.a + t.b
• r0 = a r1 = b
• s0 = 1 s1 = 0
• t0 = 0 t1 = 1
q = r0/r1
r2 = r0 - r1*q
s2 = s0 - s1*q
t2 = t0 - t1*q
Extended Euclidean Algorithm
i q r0 s0 t0 r1 s1 t1 r2 s2 t2
252 1 0 198 0 1
1 1 54 1 -1
1
2
• Definition 1
• If a and m are relatively prime integers and m > 1, then
an inverse of a modulo m exists. Furthermore, this
inverse is unique modulo m.
a.a-1 ≡ 1 (mod m)
Linear Congruences
• Example
• Find an inverse of 3 modulo 7 by first finding Bézout
coefficients of 3 and 7.
• SoluAon
Linear Congruences
• Example
• Find an inverse of 3 modulo 7 by first finding Bézout
coefficients of 3 and 7.
• SoluAon
• Because gcd(3, 7) = 1, an inverse of 3 modulo 7 exists.
• The Euclidean algorithm ends quickly when used to find
the greatest common divisor of 3 and 7:
7 = 2 · 3 + 1.
• From this equaAon we see that
−2 · 3 + 1 · 7 = 1.
• Inverse of 3 modulo 7 is -2 or 5, -9, 12, …
Linear Congruences
• Example
• Find an inverse of 101 modulo 4620.
• Solution
• Try it yourself.
Linear Congruences
• Algorithm for finding inverse of a modulo m
• Find a-1 such that
a-1.a ≡ 1 (mod m)
• Algorithm:
• Find s, t such that: sa + tm = gcd(a, m) = 1 (using
extended gcd)
• a-1 = s
int inverse(int a, int m) {
int s, t;
if (extended_gcd(a, m, s, t) == 1)
return s;
return 0; //error
}
Linear Congruences
• Solution for congruence equation:
ax ≡ b (mod m)
x ≡ a-1b (mod m)
• Ex:
7x ≡ 5 (mod 10)
x ≡ 7-1.5 (mod 10)
x ≡ 3.5 (mod 10) (since 7-1 ≡ 3.5 (mod 10))
x ≡ 15 (mod 10)
x ≡ 5 (mod 10)
Exercise
• Lan buys 15 candy boxes. She opens all boxes and
distributes candies into 8 disks such that all disks
contain a same number of candies. After
distributing candies into disks, Lan find that there
are 3 candies left.
• How many candy does each box contain ?
The Chinese Remainder Theorem
• In the first century, the Chinese mathematician
Sun-Tsu asked:
• There are certain things whose number is unknown.
When divided by 3, the remainder is 2; when divided by
5, the remainder is 3; and when divided by 7, the
remainder is 2. What will be the number of things?
The Chinese Remainder Theorem
• Tính S = 2*70 + 3*21 + 2*15
• x ≡ S (mod 105)
• If gcd(a, m) = 1, then
aφ(m) ≡ 1 (mod m).
Euler theorem
• Euler func*on:
• The value of the Euler φ-func+on at the posi*ve integer
n is defined to be the number of posi*ve integers less
than or equal to n that are rela*vely prime to n.
• Example:
• φ(6) = 2 (1,2,3,4,5, 6)
• φ(10) = 4 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)