0% found this document useful (0 votes)
32 views69 pages

Slides15 Number Theory

Uploaded by

Selene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views69 pages

Slides15 Number Theory

Uploaded by

Selene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Number theory

Pham Nguyen Khang


Contents
• Divisibility and Modular Arithmetic
• Primes and Greatest Common Divisors
• Solving Congruences
• Applications of Congruences
Divisibility
• Definition (Divisibility - Chia hết)
• If a and b are integers, a != 0, we say that a divides b if
there is an integer c such that b = ac, or equivalently, if
b/a is an integer.
• When a divides b we say that a is a factor (thừa số) or
divisor (số chia, ước số) of b, and b is a multiple (bội số)
of a.
• a | b denotes that a divides b (a chia hết b hoặc b chia
hết cho a).
• a ∤ b when a does not divide b.
Divisibility
• Theorem 1

• 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.

• We use the notation a ≡ b (mod m) to indicate that a is


congruent to b modulo m. We say that a ≡ b (mod m) is a
congruence and that m is its modulus (plural moduli).
• If a and b are not congruent modulo m, we write a ≢ b (mod
m).
• Note:
• Although both notations a ≡ b (mod m) and a mod m = b
include “mod,” they represent fundamentally different
concepts.
• When we use “a mod m”, think about % operator in C
language.
Modular Arithmetic
• Theorem 3
• Let a and b be integers, and let m be a positive integer.
Then
a ≡ b (mod m)

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

there is an integer k such that a = b + km


Modular Arithmetic
• Theorem 5
• Let m be a positive integer.
• If a ≡ b (mod m) and c ≡ d (mod m), then:
a + c ≡ b + d (mod m) and
ac ≡ bd (mod m).
• Corollary 2
• Let m be a positive integer and let a and b be integers.
Then
(a + b) mod m = ((a mod m) + (b mod m)) mod m
ab mod m = ((a mod m)(b mod m)) mod m.
Modular Arithmetic
• Exercises
1. Find the integer a such that
a) a ≡ 43 (mod23) and −22 ≤ a ≤0.
b) a ≡ 17 (mod29) and −14 ≤ a ≤14.
c) a ≡ −11 (mod21) and 90 ≤ a ≤ 110.
2. Show that if n | m, where n and m are integers greater
than 1, and if a ≡ b (mod m), where a and b are
integers, then a ≡ b (mod n).
3. Show that if a, b, c, and m are integers such that m ≥ 2,
c > 0, and a ≡ b (mod m), then ac ≡ bc (mod mc).
Primes
• Definition 1
• An integer p greater than 1 is called prime (số nguyên
tố) if the only positive factors of p are 1 and p. A positive
integer that is greater than 1 and is not prime is called
composite (hợp số).

• Remark: The integer n is composite if and only if there


exists an integer a such that a | n and 1 < a < n.
• Examples:
• 2, 3, 5, 7, 11, … are primes
• 4, 6, 12, 15, … are composites.
Primes
• Theorem 1 (THE FUNDAMENTAL THEOREM OF
ARITHMETIC)
• Every integer greater than 1 can be written uniquely as a
prime or as the product of two or more primes where
the prime factors are written in order of nondecreasing
size.
• Examples:
• 100 = 2.2.5.5 = 22.52,
• 641 = 641,
• 999 = 3.3.3.37 = 33.37,
• 1024 = 2.2.2.2.2.2.2.2.2.2 = 210
Primes
• Theorem 2 (trial division – chia liên tiếp)
• If n is a composite integer, then n has a prime divisor less
than or equal to !.

• It follows that an integer is prime if it is not divisible by


any prime less than or equal to its square root.

• This leads to the brute-force algorithm known as trial


division. To use trial division we divide n by all primes
not exceeding ! and conclude that n is prime if it is
not divisible by any of these primes.
Primes
• Example
• Show that 101 is prime.
• Solution
Primes
• Example
• Show that 101 is prime.
• Solution
• The only primes not exceeding 101 are 2, 3, 5, and 7.
• Because 101 is not divisible by 2, 3, 5, or 7,
• it follows that 101 is prime.
Primes
• Example
• Find the prime factorization of 7007.
• Solution
Primes
• Example
• Find the prime factorization of 7007.
• Solution
• To find the prime factorization of 7007,
• first perform divisions of 7007 by successive primes,
beginning with 2. None of the primes 2, 3, and 5 divides
7007.
• However, 7 divides 7007, with 7007/7 = 1001.
• Next, divide 1001 by successive primes, beginning with
7.
• It is immediately seen that 7 also divides 1001, because
1001/7 = 143.
Primes
• Example
• Find the prime factorization of 7007.
• Solution
• Continue by dividing 143 by successive primes,
beginning with 7.
• Although 7 does not divide 143, 11 does divide 143, and
143/11 = 13.
• Because 13 is prime, the procedure is completed.
• It follows that 7007 = 7·1001 = 7·7·143 = 7·7·11·13.
Consequently, the prime factorization of 7007 is
7.7.11.13 = 72.11.13.
Primes
• The Sieve of Eratosthenes
• is used to find all primes not exceeding a specified
positive integer n.
• Example
• Find the primes not exceeding 100.
• Solution
Primes
• The Sieve of Eratosthenes
• is used to find all primes not exceeding a specified positive
integer n.
• Example
• Find the primes not exceeding 100.
• Solution
• 2 is a prime
• Delete numbers that are divisible by 2, greater than 2 (4, 6, 8,
10, …)
• Because 3 is the first integer greater than 2 that is left
• All those integers divisible by 3, greater than 3, are deleted (6,
9, 12, 15, 18, …)
Primes
• The Sieve of Eratosthenes
• is used to find all primes not exceeding a specified posi3ve
integer n.
• Example
• Find the primes not exceeding 100.
• Solu3on
• Because 5 is the next integer le> a>er 3, those integers
divisible by 5, other than 5, are deleted.
• The next integer le> is 7, so those integers divisible by 7,
other than 7, are deleted.
• Because all composite integers not exceeding 100 are
divisible by 2, 3, 5, or 7, all remaining integers except 1 are
prime.
Primes
Primes
Primes
Primes
Primes
• Sieve of Eratosthenes Algorithm
int p[1001];
void Eratosthenes(int n) {
for (int i = 2; i <= n; i++)
p[i] = 1;

for (int i = 2; i*i <= n; i++)


if (p[i])
for (int j = i*i; j <= n; j += i)
p[j] = 0;
}
Primes
• Theorem 3
• There are infinitely many primes.

• Theorem 4 (THE PRIME NUMBER THEOREM)


• The ratio of the number of primes not exceeding x and
x/ ln (x) approaches 1 as x grows without bound. (Here
ln x is the natural logarithm of x.)
Greatest Common Divisors and
Least Common Multiples
• Defini&on 1 (Greatest Common Divisor)
• Let a and b be integers, not both zero.
• The largest integer d such that d | a and d | b is called
the greatest common divisor of a and b. The greatest
common divisor of a and b is denoted by gcd(a, b).
• Example
• What is the greatest common divisor of 24 and 36?
• Solu%on: The posiBve common divisors of 24 and 36 are
1, 2, 3, 4, 6, and 12. Hence, gcd(24, 36) = 12.
Greatest Common Divisors and
Least Common Multiples
• Example
• What is the greatest common divisor of 17 and 22?
• Solution: The integers 17 and 22 have no positive
common divisors other than 1, so that gcd(17, 22) = 1.
• Because it is often important to specify that two integers
have no common positive divisor other than 1.
Greatest Common Divisors and
Least Common Multiples
• Definition 2
• The integers a and b are relatively prime (nguyên tố
cùng nhau) if their greatest common divisor is 1.
• Example
• 17 and 22 are relatively prime, because gcd(17, 22) = 1.
• Definition 3
• The integers a1, a2, ..., an are pairwise relatively prime
(nguyên tố cùng nhau theo từng cặp/đôi một nguyên tố
cùng nhau) if gcd(ai,aj) = 1 whenever 1 ≤ i < j ≤ n.
Greatest Common Divisors and
Least Common Mul4ples
• Find gcd(120, 500)

• Prime factorizations of 120 and 500 are


• 120 = 23 · 3 · 5
• 500 = 22 · 53
• The greatest common divisor is
• gcd(120, 500) = 2min(3, 2)3min(1, 0)5min(1, 3) = 223051 = 20.
Greatest Common Divisors and
Least Common Multiples
• Defini&on 4 (Least Common Mul&ple)
• The least common mul&ple of the posi+ve integers a
and b is the smallest posi+ve integer that is divisible by
both a and b. The least common mul+ple of a and b is
denoted by lcm(a, b).
• Example
• What is the least common mul+ple of 233572 and 2433 ?
• Solu%on: We have
lcm(233572, 2433 ) =
2max(3, 4)3max(5, 3)7max(2, 0) = 243572.
The Euclidean Algorithm
• Lemma 1
• Let a = bq + r, where a, b, q, and r are integers. Then
gcd(a, b) = gcd(b, r).

• 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

• r2 = r0 - r1*q1 s2 = s0 - s1*q1 t2 = t0 - t1*q1


• r3 = r1 - r2*q2 s3 = s1 - s2*q2 t3 = t1 - t2*q2
• …
• rn = rn-2 - rn-1*qn-1 sn = sn-2 - sn-1*qn-1 tn = tn-2 - tn-1*qn-1
Extended Euclidean Algorithm
i q r0 s0 t0 r1 s1 t1 r2 s2 t2
252 1 0 198 0 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

q = r0/r1 r0 = r1; r1 = r2;


r2 = r0 - r1*q s0 = t1; s1 = s2;
s2 = s0 - s1*q t0 = t1; r1 = t2;
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 198 0 1 54 1 -1 54 1 -1

q = r0/r1 r0 = r1; r1 = r2;


r2 = r0 - r1*q s0 = t1; s1 = s2;
s2 = s0 - s1*q t0 = t1; r1 = t2;
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 198 0 1 54 1 -1 54 1 -1
2 3 54 1 -1 36 -3 4 36 -3 4

q = r0/r1 r0 = r1; r1 = r2;


r2 = r0 - r1*q s0 = t1; s1 = s2;
s2 = s0 - s1*q t0 = t1; r1 = t2;
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 198 0 1 54 1 -1 54 1 -1
2 3 54 1 -1 36 -3 4 36 -3 4
3 1 36 -3 4 18 4 -5 18 4 -5

q = r0/r1 r0 = r1; r1 = r2;


r2 = r0 - r1*q s0 = t1; s1 = s2;
s2 = s0 - s1*q t0 = t1; r1 = t2;
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 198 0 1 54 1 -1 54 1 -1
2 3 54 1 -1 36 -3 4 36 -3 4
3 1 36 -3 4 18 4 -5 18 4 -5
4 2 18 4 -5 0 -11 14 0 -11 14

18 = 4 x 252 + (-5) x 198


q = r0/r1 r0 = r1; r1 = r2;
r2 = r0 - r1*q s0 = t1; s1 = s2;
s2 = s0 - s1*q t0 = t1; r1 = t2;
t2 = t0 - t1*q
int extended_gcd(int a, int b, int& s, int& t) {
int r0 = a, r1 = b, s0 = 1, t0 = 0, s1 = 0, t1 = 1;
int r2, s2, t2, q;
while (r1 != 0) {
q = r0/r1;
r2 = r0 - r1*q; s2 = s0 - s1*q; t2 = t0 - t1*q;
r0 = r1; r1 = r2;
s0 = s1; s1 = s2;
t0 = t1; t1 = t2;
}
s = s0; t = t0;
return r0;
}
gcds as Linear Combinations
• Lemmas:
• If a, b, and c are positive integers such that gcd(a,b) = 1
and a | bc, then a | c.

• If p is a prime and p|a1a2···an, where each ai is an integer,


then p|ai for some i.

• Let m be a positive integer and let a, b, and c be


integers. If ac ≡ bc (mod m) and gcd(c,m) = 1, then a ≡ b
(mod m).
Linear Congruences
• A congruence of the form
ax ≡ b (mod m),
where m is a positive integer, a and b are integers,
and x is a variable, is called a linear congruence.

• 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)

• x ≡ 2*70 + 3*21 + 2*15


• = 233 (mod 105)
• x ≡ 23 (mod 105)
The Chinese Remainder Theorem
The Chinese Remainder Theorem
• Compute:
• m = m1.m2…mn
• Mk = m/mk (for k = 1..n)
• Solve:
• Mkyk ≡ 1 (mod mk) (for k = 1..n)
• yk ≡ Mk-1 (mod mk)
• Solu>on:
• x ≡ a1M1y1 + a2M2y2 + … + anMnyn (mod m)
The Chinese Remainder Theorem
• Compute:
• M = 3.5.7 = 105
• M1 = 5.7 = 35 M2 = 3.7 = 21
• M3 = 3.5 = 15
• Solve:
• 35y1 ≡ 1 (mod 3)è y1 ≡ 2 (mod 3)
• 21y2 ≡ 1 (mod 5)è y2 ≡ 1 (mod 5)
• 15y3 ≡ 1 (mod 7)è y3 ≡ 1 (mod 7)
• Solution:
• x ≡ 2 · 35 · 2 + 3 · 21 · 1 + 2 · 15 · 1 (mod 105)
• x ≡ 233 ≡ 23 (mod 105)
Back substitution
• Example:
• Use the method of back substitution to find all integers x
such that x ≡ 1 (mod 5), x ≡ 2 (mod 6), and x ≡ 3 (mod 7).
• Solution:
Back substitution
• Example:
• Use the method of back subs5tu5on to find all integers x such
that x ≡ 1 (mod 5), x ≡ 2 (mod 6), and x ≡ 3 (mod 7).
• Solu5on:
• Rewrite x ≡ 1 (mod 5) as x = 5t + 1
• Subs5tu5ng this expression to the second congruence gives:
5t + 1 ≡ 2 (mod 6)
• Rewrite 5t + 1 ≡ 2 (mod 6) as 5t ≡ 1 (mod 6)
• Solving it gives t ≡ 5 (mod 6)
• Rewrite t = 6u + 5
• Subs5tu5ng back to x: x = 5(6u+5) + 1 = 30u + 26.
• 30u + 6 ≡ 3 (mod 7) => u ≡ 6 (mod 7) => u = 7v + 6
• Subs5tu5ng back to x: x = 30(7v + 6) + 26 = 210v + 206
• x ≡ 206 (mod 210).
Fermat’s little theorem
• If p is prime and a is an integer not divisible by p,
then
ap−1 ≡ 1 (mod p).
• Furthermore, for every integer a we have
ap ≡ a (mod p).
Fermat’s little theorem
• Example: find 7222 % 11.
• Solution:
• 710 ≡ 1 (mod 11) (By Fermat’s little theorem)
• (710)22 ≡ 1 (mod 11)
• 7220 ≡ 1 (mod 11)
• 7220.72 ≡ 1.72 (mod 11)
• 7222 ≡ 72 (mod 11)
• 7222 ≡ 49 (mod 11)
• 7222 ≡ 5 (mod 11)
• So, 7222 % 11 = 5
Euler theorem
• Euler function:
• The value of the Euler φ-function at the positive integer
n is defined to be the number of positive integers less
than or equal to n that are relatively prime to n.
• Example:
• φ(6) = 2 (1,2,3,4,5, 6)
• φ(10) = 4 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

• 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)

• If m = p1k1.p2k2…pnkn (pi’s are primes)


φ(m)= m(1-1/p1)(1 – 1/p2)…(1 – 1/pn)
Euler theorem
• If gcd(a, m) = 1, then
aφ(m) ≡ 1 (mod m).
• Example:
• Find the last digit of 32019.
• SoluDon:
Euler theorem
• If gcd(a, m) = 1, then
aφ(m) ≡ 1 (mod m).
• Example:
• Find the last digit of 32019.
• Solution:
• Find 32019 % 10.
• 34 ≡ 1 (mod 10) (By Euler’s theorem, φ(10) = 4)
• (34)504 ≡ 1 (mod 10)
• 34 x 504 ≡ 1 (mod 10)
• 34 x 504.33≡ 33 (mod 10)
• 32019 ≡ 27 (mod 10)
• 32019 ≡ 7 (mod 10)
• So, the last digit of of 32019 is 7.

You might also like