Professional Documents
Culture Documents
Integer Divisibility
Integer Divisibility
Integer Divisibility
Adamchik 1
Integer Divisibility
Victor Adamchik
Fall of 2005
Plan
1. Basics of divisibility
2. Prime numbers
3. Perfect numbers
Notations
- set of integers
- set of positive integers (also , also )
- set of nonnegative integers (also 0 )
- logical AND
- logical OR
- exist (existential quantifier)
! - exist exactly one (unique existential quantifier)
- any (universal quantifier)
x - integer part of x (or the floor function)
Basics of divisibility
In this chapter, we will discuss the divisibility of integers, the set of integers is denoted by . We
will give a few detailed proofs of some of the basic facts about divisibility. Most of the properties
are quite obvious, but it is still a good idea to know how to prove them.
Definition.
An integer b 0 divides another integer a iff k that a k b.
V. Adamchik 21-127: Concepts of Mathematics
Example. 3 12 but 5 12
Exercise. Let a and b be positive integers and a b. How many positive integers not
exceeding a are divisible by b? In other words, find such c that b c a and b c
Solution. All numbers divisible by b are in the form b k, where k . They are positive and do
not exceed a,
a
0 b k a or 0 k b
(1) 1 a, 1 a and a 0.
(2) Reflexivity: a a.
(3) Transitivity: a b b c a c.
(4) Not-quite antisymmetry: a b b a a b a b.
(5) if a b a c a n b m c for any integers n and m
Proof.
a a a 1 a a
and therefore x y 1 (there are no zero-divisors in the integers). It follows that either y x 1
or y x 1. But x 1 implies a b, and x 1 implies b a.
V. Adamchik 3
Consider n b m c
nb mc xan y am a xn ym a nb mc
It follows
a nb mc
Application of Theorem 2.
Do there exist integers x, y, and z such that 6 x 9y 15 z 107?
Since 3, 6 and 9 has a common divisor 3 than 3 must divide its linear combination
3 6x 9y 15 z 3 107 which is wrong.
20
15
10
Primes
Observation. Every positive integer has at least two divisors: 1 and itself
Definition. Integer p 1 is called a prime if its only positive divisors are 1 and p.
Otherwise it is called a composite.
V. Adamchik 21-127: Concepts of Mathematics
The number 1 is a special case which is considered neither prime nor composite
Define
p p1 p2 … pn 1.
But then, there is some prime that divides p. Since our list is supposedly complete that prime must
be, say, pr .
We have that pr p
pr p
pr p p1 p2 … pn pr 1
pr p1 p2 … pn
But then pr 1.
A contradiction.
QED - end of proof ("quod erat demonstrandum").
Sieve of Eratosthenes:
(Greek astronomer, 195BC)
Write down the integers from 2 to the highest number n you wish to include in the table. Cross out
all numbers 2 which are divisible by 2. Cross out all numbers 3 which are divisible by 3,
then by 5 and so on. Continue until you have crossed out all numbers divisible by n .
V. Adamchik 5
Why do we stop at n ?
Because the next number to cross must be n since we cross all numbers with divisors n .
Observation:
6 3 3
7 5 2
8 5 3
9 7 2
10 7 3
18 11 7
Goldbach made the conjecture that every odd number > 5 is equal to the sum of three primes.
Euler replied that Goldbach's conjecture was equivalent to the statement that every even number >
2 is equal to the sum of two primes.
p1 p2 2n
It is known to be true for for numbers through 6 1016 (checked numerically in 2003)
Mersenne numbers
For some years, people believed that if p is prime, then so is 2 p 1:
22 1, 23 1, 25 1, ...
211 1 2047 23 89
Mersenne Conjecture (15 century, by French monk Marin Mersenne) 2 p 1 is prime for
p 2, 3, 5, 7, 13, 17, 19, 31, 67, 127 , 257 and composite for all other positive integers p < 257.
V. Adamchik 21-127: Concepts of Mathematics
It took a few of centuries to show that the conjecture was wrong. Only in 1947 the range up to 258
was checked! It turned out that
225,964,951 1
Proof. By contradiction - we assume that 2 p 1 is prime, but p is not prime. Let p be a composite
number, p r s. Consider the following polynomial
xr s
1
It can be written as
xr s 1 xs 1 xs r 1 xs r 2 ... xs 1
Perfect numbers
Definition. An positive integer is a perfect number if it equals the sum of its proper divisors (not
including itself).
6=1+2+3
28 = 1 + 2 + 4 + 7 + 14
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
8128 = ...
V. Adamchik 7
Question. What is the next perfect number? It seems it should not be a problem to answer this by
writing Java or C program.
This question is much much harder.... It is not known if any odd perfect numbers exist.
6=1+2+3 =2*3
28 = 1 + 2 + 3 + 4 + 5 + 6 +7 = 4 * 7
496 = 1 + 2 + 3 +... + 31 = 16 * 31
Generally,
2n 1
2n 1 , when n is prime
This is a relation between the perfect and the Mersenne primes. So the search for Mersenne primes
is also the search for even perfect numbers!
V. Adamchik 1
Integer Divisibility
Victor Adamchik
Fall of 2005
Plan
1. Division Algorithm
2. The fundamental theorem of arithmetic
3. Counting the number of divisors
a q b r, where 0 r b.
Proof.
Case a) is trivial.
V. Adamchik 21-127: Concepts of Mathematics
Case b).
Given that b does not divide a. Consider the following set
S a q b q a q b 0 .
Example, b 3 and a 10
q 3, 2, 1, 0, 1, ...
S is not empty. We must prove this statement. Again, two cases to consider.
If a 0, choose q 0, so a S.
Since S is the set of non-negative integers it must contain a least element, say, r 0 .
r0 min S
0 r0 a q0 b
Case 1. Let r 0 b
0 b a q0 b
Collect terms in b
a b q0 b q0 1 b
b a
V. Adamchik 3
Case 2. Let r0 b 0.
r0 b a q0 b b a q0 1 b S
Suppose that
a q0 b r0
a q1 b r1
where 0 ri b and r0 r1 .
0 q0 b q1 b r0 r1
0 b q0 q1 r0 r1
b q0 q1 r1 r0
0 b q0 q1 b
0 q0 q1 1
q0 q1
QED
Exercise. Where will the proof fail if you allow negative remainders?
V. Adamchik 21-127: Concepts of Mathematics
Proof:
By the division algorithm, we can write
a q1 p r1 and b q2 p r2 .
where 0 r1 , r2 p. Hence,
a b q1 q2 p2 q1 r2 p q2 r 1 p r1 r2
a b p q1 q2 p q1 r2 q2 r1 r1 r2
Given that p divides a b, therefore, p r1 r2 . It follows then that the remainder r1 r2 must be 0.
But then r1 or r2 must be 0, so that p divides a or b. QED
p
Let 2 q
, in lowest terms - no common divisors. Then
p2
2 2 q2 p2 2 p2 2 p p 2 p
q2
Assume p 2 c, c
Then
2 q2 p2 2 q2 4 c2 q2 2 c2 2 q2 2 q
Exercise. Where will the proof fail if you try to prove that 4 is irrational?
V. Adamchik 5
n p1 p2 … pk .
300 = 2 * 2 * 3 * 5 * 5
Proof.
First existence. We use in induction on n.
Inductive step:
If n is prime, there is nothing to show.
Otherwise, n a b where 1 a, b n.
By IH, both a and b can be written as products of primes, and our claim follows.
n p1 p2 … pk q1 q2 … qs
Since p1 divides the second product, we must have p1 q i for some i. But then p1 q i.
p2 … pk q2 … q s.
By continuing in this way, we see that each pk must be paired with q j . Apart from the order of the
factors. QED.
Corollary. Every positive integer 1 can be written uniquely (except for order) in the form
x p1 e1 p2 e2 ... pn em , pi p j for i j
Counting divisors
2i 3j 5k
Theorem. Integer
x p1 e1 p2 e2 ... pn em
Integer Divisibility
Victor Adamchik
Fall of 2005
Plan
1. Methods of Proofs (review)
2. Geometry of divisors
3. The greatest common divisor
4. Euclidean Algorithm
Methods of Proofs
The most theorems you want to prove are in the form
P Q
Direct Proofs
Proofs by Contradiction
In this method of proof we negate the result we need to prove, namely statement Q.
Therefore, we assume P and Not Q (denote as Q). In the proof flow we must arrive to some
conclusion that either contradicts our assumptions or is something obviously not true.
P Q False
x x2 is even x is even
Proof.
2
2k 2n 1
2k 4 n2 4n 1
2 k 2 n2 2n 1
Proofs by Contrapositive
Q P
In the method of Contrapositive the goal of your proof is clear - you must prove P.
Theorem. If x and y are two integers whose product is odd, then both must be odd.
Proof.
P0 kPk Pk 1 nP n
First we prove that the theorem is true in the initial case. Then we prove that if it is true for any
given case it is true for the next case. This will prove that it is true for all positive integers.
V. Adamchik 3
Counting divisors
Theorem. For any positive integer
x p1 e1 p2 e2 ... pn em
e1 1 e2 1 ... em 1
72 23 32
How does the diagram help us to do algebra? It can be used to compute GCD and LCM. Observe
that each element in the diagram generates a downward cone of divisors and upward code of multi-
ples. Therefore, the intersection of downward cones gives the GCD of two numbers, and the inter-
sectionof two upward cones gives the LCM.
Problem. A CMU football team has 100 lockers that initially closed. Student #1 opens all lockers.
Student #2 closes all even lockers. Student #3 changes the status of each locker multiple of 3.And
so on, student #k changes the status of each locker multiple of k. Which lockers are open after all
100 students have done their job?
Solution.
Think about what it takes to make a locker to end up open. It takes an odd number of changes.
Which means an odd number of divisors.
Exercise. How many positive integers less than 100 have exactly 6 divisors?
V. Adamchik 5
GCD
Definition. Suppose a and b are integers. A greatest common divisor (GCD) is defined as
gcd a, b max d P d a d b .
Definition. Integers a and b are relatively prime (or coprime) iff gcd a, b 1
gcd a, b gcd b, a b
Proof.
Let
S n a m b n, m , n a m b 0
Set S has a least element. Let us call it d. We need to prove that d is a gcd.
r a qd a q na mb 1 qn a qm b
Next we prove that d is a greatest. Assume that there is c such that c a and c b. Therefore, c
divides their linear combination c n a m b c d.
V. Adamchik 21-127: Concepts of Mathematics
Finally we prove that d is unique. Let d1 and d2 be gcds of a and b. Suppose d1 is a greatest, and
d2 is a common divisor. Then from the previous paragraph, we see that d2 d1 . Reversing rules,
then d2 d1 . Therefore, d1 d2 .
QED
gcd 56, 24 8 56 1 24 2
Euclidean Algorithm
Given a pair of numbers a and b.
Find gcd a, b
Find such n, m that gcd a, b n a m b
Proof. Denote
d1 gcd a, b
d2 gcd b, r
a b q1 r 1, 0 r1 b
b r1 q2 r 2, 0 r2 r1
r1 r2 q3 r 3, 0 r3 r2
...
rk 2 rk 1 qk r k, 0 rk rk 1
rk 1 rk qk 1 0
V. Adamchik 7
Proof. Let
S r1 , r2 , ..., rk
Set S contains a least element. This means that the above division will definitely terminate. Next.
QED
203 2 91 21
91 4 21 7
21 3 7 0
Question. When does the worst performance of the Euclidean Algorithm occur?
21 1 13 8
13 1 8 5
8 1 5 3
5 1 3 2
3 1 2 1
2 2 1 0
Therefore, if we set all quotients qi to 1 in the Euclidean algorithm, we immediately obtain the
following equation for the remainders
rk 2 rk 1 rk
which defines Fibonacci numbers backwards. We will talk about these numbers in more details
later in the course.
Theorem (1845, G.Lame, french mathematician) For two positive m and n m the Euclidean
algorithm computes GCD m, n in no more that log n 1 steps.
5 1
2
as a solution of
x2 x 1 0
V. Adamchik 1
Integer Divisibility
Victor Adamchik
Fall of 2005
Plan
1. Extended Euclidean Algorithm
2. Continued Fractions
a b q1 r 1, 0 r1 b
b r1 q2 r 2, 0 r2 r1
r1 r2 q3 r 3, 0 r3 r2
... ... ...
rk 2 rk 1 qk r k, 0 rk rk 1
rk 1 rk qk 1 0
Exercise. Apply the Euclidean Algorithm to two real numbers. What will this procedure yield?
203 2 91 21
91 4 21 7
21 3 7 0
V. Adamchik 21-127: Concepts of Mathematics
21 = 203 - 2 * 91
7 = 91 - 4 * 21
7 91 4 21 91 4 203 2 91 9 91 4 203
The procedure we have followed above is a bit messy because of all the back substitutions we have
to make. It is possible to reduce the amount of computation involved in finding n and m by doing
some auxillary computations as we go forward in the Euclidean algorithm (and no back substitu-
tions will be necessary). This is known as the extended Euclidean Algorithm (EEA).
a b q1 r 1, r1 a b q1
b r1 q2 r 2, r2 b r1 q2
r1 r2 q3 r 3, r3 r1 r2 q3
... ... ...
rk 2 rk 1 qk r k, rk rk 2 rk 1 qk
rk 1 rk qk 1 0
a 1 0
b 0 1 q1
r1 1 q1 q2
r2 q2 1 q1 q2 q3
... ...
rk n m
where the third row is the first row minus the second row multiplied by q1
where the fourth row is the second row minus the third row multiplied by q2 and so on.
123 2 45 33
45 1 33 12
33 2 12 9
12 1 9 3
9 3 3 0
123 1 0
45 0 1 2
33 1 2 1
12 1 3 2
9 3 8 1
3 4 11
Therefore,
Applications
Recall the Die Hard movie. Willis and Jackson are supposed to disarm a bomb by measuring
exactly 4 gallons of water using only 3 and 5-gallons containers. In this section we outline the
mathematrics used for solving this kind of problems.
Problem. You have two containers that hold 17 and 55 ounces (oz). How would you measure 1
ounce?
Solution.
Perform Euclidean algorithm, find GCD and then express it as a linear combination of 17 and 55
55 = 17* 3 + 4
17 = 4* 4 + 1
GCD(55,17) = 13 * 17 - 4 * 55
You fill a smaller container 12 times 12*17 = 204 and empty it into the larger container
At this stage, you have an empty smaller container and 39oz in the larger container. On the next
step (13th) you fill 16 oz into the larger container, leaving 1oz in the smaller one.
Problem. Michael Klipper - our great TA - can debug any C++ code program in 10 mins and any
Java program in 6 mins. If he works continiously 104 mins, how many programs can he debug?
Solution.
Write an equation
10 x 6 y 104 or 5 x 3 y 52
Since
Multiply it by 52
52 = 104*3 - 52*5
52 104 5k 3 3k 52 5
104 5k 0 52 104
3
k 5
3k 52 0
This gives us three possible solutions k 18, 19, 20. Therefore, he can debug
14 java 2 c OR 9 java 5 c OR 4 java 8 c programs.
Continued Fractions
a b q1 r 1, 0 r1 b
b r1 q2 r 2, 0 r2 r1
r1 r2 q3 r 3, 0 r3 r2
... ... ...
rk 2 rk 1 qk r k, 0 rk rk 1
rk 1 rk qk 1 0
a
From the first line we express b
V. Adamchik 5
a r1 a 1
q1 q1
b b b b
r1
b
From the second line we express r1
b r2 b 1
q2 q2 r1
r1 r1 r1 r2
b a
Substitute r1
into the equation for b
a 1
q1 1
b q2 r1
r2
a 1
q1 1
b q2 1
q3 r2
r3
Generally
a r1
b
q1 b
b r2
r1
q2 r1
r1 r3
r2
q3 r2
... ...
rk 2 rk
rk 1
qk rk 1
rk 1
rk
qk 1 0
We will get
a 1
q1 1
b q2 1
q3 1
q4 ... qk 1
37 1
3 1
11 2 1
1 3
V. Adamchik 21-127: Concepts of Mathematics
21 1
1 1
13 1 1
1 1
1 1
1 1
1
1
x2 x 6 0
We begin with
6
x 1
x
2
Then express x in the right hand side by 1 x
:
6
x 1 6
1 x
6
x 1 6
1 1 6
x
Continuing this process, we produce an infinite continued fraction, that approximate one of the
roots. Here is Mathematica section
6
ListPlot Table Nest 1 &, 1., k , k, 1, 30 ,
#
PlotStyle Hue 0.7 , PointSize 0.01 ;
-1.5
-2
-2.5
-3
-3.5
5 10 15 20 25 30
V. Adamchik 1
Integer Divisibility
Victor Adamchik
Fall of 2005
Plan
1. Introduction to Diophantine Equations
2. Linear Diophantine Equations
3. Positive solutions to LDE
Introduction
Definition. Let P x, y, ... is a polynomial with integer coefficients in one or more variables. A
Diophantine equation is an algebraic equation
P x, y, z, ... 0
For example,
2x 3y 11
7 x2 5 y2 2x 4y 11 0
y3 x3 z3
The problem to be solved is to determine whether or not a given Diophantine equation has solu-
tions in the domain of integer numbers.
In 1900 Hilbert proposed 23 most important unsolved problems of 20th century. His 10th problem
was about solvability a general Diophantine equation. Hilbert asked for a universal method of
solving all Diophantine equations.
V. Adamchik 21-127: Concepts of Mathematics
1946. Turing invented Universal Turing Machine and discovered basic unsolvable problems
Theorem (Y. Matiyasevich) There is no algorithm which, for a given arbitrary Diophantine equa-
tion, would tell whether the equation has a solution or not.
By the way, Goldbach's conjecture (which was mentioned a few lectures back) is Hilbert's 8th
problem.
ax by c
It is not obvious that all such equations solvable. For example, the equation
2x 2y 1
Some linear Diophantine equations have finite number of solutions, for example
2x 4
Thereom.
The linear equation a, b, c
ax by c
Proof.
)
gcd a, b a gcd a, b b
gcd a, b xa yb gcd a, b c
Given
gcd a, b c z , c gcd a, b z
x1 , y1 , gcd a, b x1 a y1 b.
Multiply this by z:
z gcd a, b a x1 z b y1 z
c a x1 z b y1 z
a n b m gcd a, b
Multiply this by c
a n c b m c gcd a, b c
Divide it by gcd
n c m c
a b c
gcd a, b gcd a, b
V. Adamchik 21-127: Concepts of Mathematics
ax by c
n c m c
x0 ; y0
gcd a, b gcd a, b
56 x 72 y 40
GCD 56, 72 8 4 56 3 72
4 40 3 40
x0 ; y0
8 8
x0 20; y0 15
By the extended Euclidean algorithm we find gcd and such n and m that
gcd a, b a n b m
gcd a, b c a n c b m c
gcd a, b c a n c b m c a b k a b k
a nc bk b mc ak gcd a, b c
nc bk mc ak
a b c
gcd a, b gcd a, b
It can be rewritten as
nc bk mc ak
c a b
gcd a, b gcd a, b gcd a, b gcd a, b
or
b k a k
c a x0 b y0
gcd a, b gcd a, b
k 0, 1, 2, ...
bk ak
x x0 y y0
gcd a, b gcd a, b
k 0, 1, 2, ...
56 x 72 y 40
GCD 56, 72 8 4 56 3 72
nc bk
x
gcd a, b gcd a, b
mc ak
y
gcd a, b gcd a, b
Hence
4 40 72 k
x 20 9 k
8 8
V. Adamchik 21-127: Concepts of Mathematics
3 40 56 k
y 15 7 k
8 8
nc bk
x
gcd a, b gcd a, b
mc ak
y
gcd a, b gcd a, b
nc bk 0
mc ak 0
To find out how many positive solutions a given equation has let us consider two cases
1. ax by c, gcd a, b 1, a, b 0
2. ax by c, gcd a, b 1, a, b 0
It follows that in the first case, the equation has a finite number of solutions
nc mc
k
b a
nc b k 0
mc a k 0
4x 7y 117
Solution.
V. Adamchik 7
GCD 4, 7 1 2 4 1 7
The number of solutions in positive integers can be determined from the system
nc bk 0
mc ak 0
2 117 7 k 0
1 117 4 k 0
This gives
2 117 117
k
7 4
3x 6y 5z 7
GCD 3, 6 x 2y 5z 7
Let
w x 2y
3w 5z 7
w 2 7 5k
z 1 7 3k
since
V. Adamchik 21-127: Concepts of Mathematics
GCD 3, 5 1 2 3 1 5
x 2y 14 5k
x 1 14 5k 2 l
y 0 14 5k 1 l
x 5k 2l 14
y l
z 7 3k
where
k, l 0, 1, 2, ...
V. Adamchik 1
Integer Divisibility
Victor Adamchik
Fall of 2005
Plan
1. The Money-Changing Problem
2. The Frobenius postage stamp problems
Review
ax by c
nc bk mc ak
x and y
gcd a, b gcd a, b
Positive solutions
1 ax by c, a 0, b 0
2 ax by c, a 0, b 0
Plot x 1, x 1 , x, 5, 5 ;
-4 -2 2 4
-2
-4
Let
u 3x 4 y and v 5z 6t
Solve
u v 7
We find
u 7 k1 and v k1
Next, we solve
3x 4y 7 k1
5z 6t k1
x 7 k1 4 k2
y 7 k1 3 k2
z k1 6 k3
V. Adamchik 3
t k1 5 k3
where k1 , k2 , k3 .
In the change-making problem, there given a finite set of denominations and unlimited supply of
coins. We need to represent a given value with the fewest number of coins.
1+1+1+1+1+1+1+1+1+1
1+1+1+1+1+5
5+5
10
The above problem is a simple form of the linear Diophantine problems. For a given integer N find
all solutions in non-negative integers to the equation
x1 5 x2 10 x3 25 x4 50 x5 100 x6 N
6
xk MIN
k 1
Let us imagine a NEW coin system. It uses 4, 7, 9 and 34-cent coins. The system has an obvious
flaw that makes our system more interesting. Not all amounts can be exchanged. Which amounts
can be exchanged? What is the largest amount that cannot be exchanged?
z ax by
Assuming an infinite supply of coins, we want to know what is the largest amount
d1 x1 d2 x2 ... dk xk N
Question 1. Let us choose denominations 3 and 5. What is the largest number that cannot be
decomposed?
Question 2. Choose denominations 4 and 5. What is the largest number that cannot be
decomposed?
Question 3. How about this set of denominations: 5 and 7. What is the largest number that cannot
be decompose?
Consider
ax by z, GCD a, b 1
We need to find the largest z such that the equation has NO positive solutions in x and y.
x x0 b k
y y0 a k
k 0, 1, 2, ...
..., x0 b, x0 , x0 b, ...
0 x b
y 0
Example.
3x 5y 11
nc bk mc ak
x and y
gcd a, b gcd a, b
or
x 22 5k and y 11 3k
0 x b
Therefore,
0 22 5k 5 k 4
x 2, y 1.
Exercise. Consider
V. Adamchik 21-127: Concepts of Mathematics
3x 5y 2
Theorem. Let a and b be relatively prime positive integers. That the largest positive integer that is
not representable in the form a x b y is defined by a 1 b 1 1.
Proof. Consider
U ax by 0 x b y 0
V ax by 0 x b y 0
What is Max V ?
x b 1 y 1
z b 1 a 1 b
The problem is algorithmically solved for 3 denominations and completely open for 4 and more
denominations. The problem is NP-hard. (Ramirez-Alfosin, 1996)
1=1
2=1+1
3=1+1+1
...
19 = 14 + 4 +1
V. Adamchik 7
...
36 = 15 + 15 + 6
37 = ?
d1 x1 d2 x2 ... dk xk N
x1 x2 ... xk H
where H a2 2 is the number of stamps. The two stamps problem can be solved
H 3 d2 d2 1