Math 393 Chapter 3: Primes and Greatest Common Divisors
Dr. Zhigang Han, Millersville University
3.1 Prime Numbers
• Definition: An integer greater than 1 is a prime if it has exactly two positive divisors: 1 and itself; an
integer greater than 1 is a composite if it is not a prime.
Remark: By definition, 1 is neither a prime nor a composite.
Eg 1: List the first 10 primes.
Eg 2: Prove that n2 1 is a composite for all integer n 3.
Lemma 3.1. Every integer greater than 1 has a prime divisor.
1
Theorem 3.1 (Euclid’s theorem). There are infinitely many primes.
p
Theorem 3.2. If n is a composite, then n has a prime factor not exceeding n.
Eg 3: Determine whether 227 is a prime.
• Sieve of Eratosthenes: a procedure to find all of the primes less than or equal to a given positive integer n.
2
3.3 Greatest Common Divisors and Their Properties
• Theorem 3.6. Let a and b be integers, not both 0. If (a, b) = d, then ( ad , db ) = 1.
Remark: Theorem 3.6 states that if you divide two integers by their greatest common divisor, the resulting
numbers are relatively prime.
Eg 1: Since (15, 35) = 5, ( 15 35
5 , 5 ) = (3, 7) = 1.
Theorem 3.7. If a, b, and k are integers, then (a, b) = (a + kb, b).
Eg 2: Use Theorem 3.7 to compute (2020, 2025).
Eg 3: Prove that 6n + 5 and 2n + 1 are relatively prime for all n 2 Z.
3
• Definition. A linear combination of integers a and b is a number of the form ma + nb, where m, n 2 Z.
Eg 4: Since 6 = ( 2)18 + (1)42, 6 is a linear combination of 18 and 42.
Theorem 3.8. If a and b are integers, not both 0, then (a, b) is the smallest positive linear combination of a
and b. In particular, there exist m, n 2 Z such that (a, b) = ma + nb.
Corollary. Two integers a and b are relatively prime if and only if there exist m, n 2 Z such that ma+nb = 1.
Eg 5: Prove that 5n + 7 and 3n + 4 are relatively prime for all n 2 Z.
4
Corollary. The set of all linear combinations of integers a and b is the set of all multiples of (a, b).
Eg 6: All linear combinations of 12 and 18 are 0, ±6, ±12, · · · , which are exactly all multiples of (12, 18) = 6.
Corollary. The set of all common divisors of integers a and b is the set of all divisors of (a, b).
Eg 7: All common divisors of 12 and 18 are ±1, ±2, ±3, ±6, which are exactly all divisors of (12, 18) = 6.
• Definition. Let a1 , a2 , · · · , an be integers, not all 0. The greatest common divisor of these integers,
written as (a1 , a2 , · · · , an ), is the largest integer that divides all of these integers.
Eg 8: (12, 18, 30) = 6 and (10, 15, 25) = 5.
Remark: To compute the GCD of more than two integers, you can compute the GCD two integers at a time.
Eg 9: Compute (2020, 2025, 3033).
5
3.4 The Euclidean Algorithm
• Basic facts about the GCD:
1. (a, b) = (b, a)
2. (a, b) = (|a|, |b|)
3. (a, 0) = |a|
Remark: Due to facts (2) and (3), it suffices to understand the GCD of positive integers.
• Lemma 3.3: Let a and b be integers. If a = bq + r for some q, r 2 Z, then (a, b) = (b, r).
Ca , b) = ( a- bq , b)
=
( r
, b) .
• How to find GCD (The Euclidean Algorithm): If r0 = a and r1 = b are positive integers with a b,
then (a, b) = rn , the last nonzero remainder below by successively applying the division algorithm.
r0 = r1 q 1 + r2 , where 0 < r2 < r1 ,
r1 = r2 q 2 + r 3 , where 0 < r3 < r2 ,
r2 = r3 q 3 + r 4 , where 0 < r4 < r3 ,
..
.
rn 3 = rn 2 qn 2 + rn 1, where 0 < rn 1 < rn 2,
rn 2 = rn 1 qn 1 + rn , where 0 < rn < rn 1,
rn 1 = rn qn + 0.
Eg 1: Use the Euclidean algorithm to find (187, 408).
j rj qj 408=18712 ) + 34
0 408
1 187 2
187 =
34 (5) + IF
2 34 5
3 17 2
4 ◦
34 =
1712 ) +0
5
6
• How to express (a, b) as a linear combination of a and b (The Extended Euclidean Algorithm):
If r0 = a and r1 = b are positive integers with a b, then
(a, b) = sn a + tn b,
where sn and tn are the n-th terms of the sequences defined recursively by
s0 = 1, t0 = 0,
s1 = 0, t1 = 1,
and
sj = sj 2 qj 1 sj 1 , t j = tj 2 qj 1 tj 1
for j 2, where the qj ’s are the quotients found in the Euclidean algorithm.
Eg 2: Use the extended Euclidean algorithm to find (187, 408) and express it as a linear combination of 187
and 408.
408 -
(1) 408 + 10 ) 187 =
j rj qj sj tj (2) [ 187 107408 + (1) 187 ]
✗
=
0 408 1 0
34 = (1) 408 + C- 2) 187
1 187 2 0 1
2 34 5 I -2
187 = CO) 408 + 4) 187
3 17 2 -5 11
-
4 (5)[ 34 4) 408 + C-2) 187] = .
5
17=(-57408+41) 187 .
Eg 3: Use the extended Euclidean algorithm to find (246, 194) and express it as a linear combination of 246
and 194.
j rj qj sj tj
0 246
( 246 , 194 ) =L
' °
1 194 I 0 I
2 52 3 I -
I
3 38 I -
3 4
4 14 2 4 -5 I = -41 (2461 + 52494) .
5 10 I - 11 14
6 4 2 15 -19
7 2 2 -
41 52
8 0
7
3.5 The Fundamental Theorem of Arithmetic
• Lemma 3.4. Let a, b, c 2 N. If (a, b) = 1 and a|bc, then a|c.
be then be (r 2) since ( cm + rn ) EZ
since a
/ ,
=
age c- .
since la , b) =L then ma +
nb = 1 then a / c.
Cma + crib = C
Cma + ann = C
atom + Rn ) = C
Lemma 3.5. Let a1 , a2 , · · · , an 2 N and let p be a prime. If p|a1 a2 · · · an , then p|ai for some i (1 i n).
proof :
Assume plat Akel
' "
het aiiaj , i -
i
, an
E N and let p be a
prime .
pla ,
* Case 1 : assume P lake ,
consider n = 1 .
If
,
then play .
so the result holds for n = 1 .
then plai where I ≤ i ≤ k -11 .
for some k c- Z
,
assume
pla, ay . . .
ah
then play . *
Case 2 : assume
p fake ,
then (p ,
ah + , ) = 1
for some 1 ≤ i ≤ k .
and Pt Caras "
ah )ah+ ,
plain
'
We must show that .
ah ,,
then play .
lemma 3- 4 plain ah
By ,
-
where i≤ i ≤ A -11 inductive
By hyp .
, pla , ,
i . .
plate .
• The Fundamental Theorem of Arithmetic. Every integer n 2 can be written in the form of
n = pn1 1 pn2 2 · · · pn` ` ,
where the ni ’s are positive integers and the pi ’s are distinct primes. Furthermore, the factorization is unique
except for the order of the factors.
8
Proposition. If a = pa11 pa22 · · · pakk is the prime factorization of a, then
1. all positive divisors of a are of the form
d = pd11 pd22 · · · pdkk , where 0 di ai for i = 1, 2, · · · , k.
2. the total number of all positive divisors of a is
N = (1 + a1 )(1 + a2 ) · · · (1 + ak ).
2000000
Eg 1: List all positive divisors of 200.
= 2×106
200 = 23 .
g-
2
"
/ \ =L (2×5)
2 100
N ( ' + 3) (1+2)
27
=
,, =
.
56
250 = 12 .
225 N= (1+7) (1+6)=56 .
''
55
Proposition. If a = pa11 pa22 · · · pakk and b = pb11 pb22 · · · pbkk are prime factorizations of a and b, where some
exponents may be zero, then
1. the greatest common divisor
mk
(a, b) = pm 1 m2
1 p2 · · · pk , where mi = min(ai , bi ) for i = 1, 2, · · · , k.
2. the total number of all positive common divisors of a and b is
N = (1 + m1 )(1 + m2 ) · · · (1 + mk ), where mi = min(ai , bi ) for i = 1, 2, · · · , k.
a = 23 .
31.57
N= ( 1+3 )( It 1) (1+0)
b- -
24.32.50
( a. b) =L ? 31.50 =
Eg 2: List all positive common divisors of 1000 and 420.
?
1000=23.53 ( 1000,420) = 2 g-
420 =L? 3.5.7
/ \
N = (1+1) (1+2)=6
42 10
^ ^
7 6 25
^
9
23
Definition. Let a and b be nonzero integers. The least common multiple of a and b, denoted by [a, b], is
the smallest positive integer that is divisible by both a and b.
Eg 3: [5, 15] = 15 and [12, 18] = 36.
• Proposition. If a = pa11 pa22 · · · pakk and b = pb11 pb22 · · · pbkk are prime factorizations of a and b, where some
exponents may be zero, then the least common multiple
Mk
[a, b] = pM 1 M2
1 p2 · · · pk , where Mi = max(ai , bi ) for i = 1, 2, · · · , k.
F
A =
23 31. .
g-
2? 3? g-
b =
[ a b)
,
= 2 ? 5.57
Theorem 3.16. If a and b are positive integers, then (a, b) · [a, b] = ab.
Eg 4: Use Theorem 3.16 to compute [2220, 2225].
( 2220,2225) [ 2220,2225 ] .
=
(2220×2225)
( 2220 ) ( 2225)
[ 2220,2225 ] =
( 2220 , 2225 )
(2220 ) ( 2225)
=
10 = 987 900 .
3.6 Factorization Methods
• Factoring by trial division: By Theorem 3.2, a positive integer n 2 is either a prime or has a prime
p
factor not exceeding n. We can use the following steps to completely factor n.
p
1. Divide n by all primes p n (starting from the smallest and not skipping any).
(a) If none yields an integer answer, then n is a prime and we are done.
(b) Otherwise we have a prime factor p1 . Repeatedly divide by p1 until the answer is no longer an integer
so that
n = pa11 n1 , where n1 is not divisible by p1 .
p
2. Divide n1 by all primes p such that p1 < p n1 (starting from the smallest and not skipping any).
(a) If no such p exists or none yields an integer answer, then n1 is a prime and we are done.
(b) Otherwise we have a prime factor p2 . Repeatedly divide by p2 until the answer is no longer an integer
so that
n1 = pa22 n2 and n = pa11 pa22 n2 , where n2 is not divisible by p2 .
3. If necessary, repeat step 2 with n1 replaced by n2 and p1 replaced by p2 , and so on.
Eg 1: Factor 339 completely.
Eg 2: Factor 1, 003, 219 completely.
Eg 3: Factor 10, 573 completely.
11
Lemma 3.9. If n is an odd integer, then there is a one-to-one correspondence between expressions of n as a
product of two integers and expressions of n as a di↵erence of two perfect squares.
Eg 4: 77 = (9)2 (2)2 = (11)(7) and 77 = (39)2 (38)2 = (77)(1). Note how the first expression of 77 as a
di↵erence of two squares helps with the prime factorization of 77, but the second one does not.
• Fermat factorization: To factor an odd integer n as a product of two integers,
p n+1
1. Plug each integer s with n s 2 (starting from the smallest) into s2 n until the answer becomes
a perfect square: s2 n = t2 .
2. Then, n = s2 t2 = (s + t)(s t).
Eg 5: Factor 10, 573 completely.
Eg 6: Factor 419 completely.
12
3.7 Linear Diophantine Equations
• Diophantine equations: A Diophantine equation is an equation which is to be solved over the integers.
A linear Diophantine equation in two variables is an equation ax + by = c, where a, b, and c are integers.
Eg 1: The Diophantine equation 3x + 5y = 2 has at least one solution x = 1 and y = 1. (In fact, it has
infinitely many solutions.)
Eg 2: The Diophantine equation 2x + 4y = 1 has no solutions since for all integers x and y, the left side of
the equation is always even, which will never be equal to 1.
Theorem 3.23. Let a, b, c 2 Z and (a, b) = d. Consider the Diophantine equation ax + by = c.
1. If d - c, then the equation has no solutions.
2. If d | c, then the equation has infinitely many solutions of the form
b a
x = x0 + t, y = y0 t,
d d
where x = x0 and y = y0 is a particular solution of the equation and t 2 Z.
Eg 3 (Eg 1 revisited): Consider the Diophantine equation 3x+5y = 2. Since a = 3 and b = 5, d = (3, 5) = 1,
which divides c = 2. Thus, the equation has infinitely many solutions. Since x = 1 and y = 1 is a particular
solution, all solutions of the equation are
x= 1 + 5t, y = 1 3t, where t 2 Z.
Eg 4 (Eg 2 revisited): Consider the Diophantine equation 2x+4y = 1. Since a = 2 and b = 4, d = (2, 4) = 2,
which does not divide c = 1. Thus, the equation has no solutions.
13
How to find a particular solution: Basically there are two di↵erent ways:
1. By inspection.
2. Use the extended Euclidean algorithm to find m and n such that ma + nb = (a, b) = d. Then, a particular
solution of ax + by = c (when d | c) is
c c
x0 = m and y0 = n.
d d
Eg 5: Solve the Diophantine equation 9x + 12y = 30.
Eg 6: Solve the Diophantine equation 408x + 187y = 34.
j rj qj sj tj
0
1
2
3
4
5
14
Eg 7: Solve the Diophantine equation 98x 21y = 35.
j rj qj sj tj
0
1
2
3
4
5
Eg 8: Each adult ticket for a theme park costs $194 and each child ticket costs $178. If more child tickets
were sold than adult tickets and the total sale was $37, 000, how many tickets were sold for each type?
j rj qj sj tj
0
1
2
3
4
5
15