Integer Divisibility

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

V.

Adamchik 1

Integer Divisibility
Victor Adamchik

Fall of 2005

Lecture 1 (out of seven)

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

We also say that b is a factor (or divisor) of a.

One frequently writes b a to indicate that b divides a.

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

Therefore, there are floor( ab ) or a


b
such integers

Theorem 1. For all integers a, b, c

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

(1) and (2) follow immediately

a a a 1 a a

(3) Given b x a and c y b.


Then c y b y x a x y a, so a | c

(4) Given b x a and a y b.


Then a xy a a 1 xy 0,

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

(5) Given b x a and c y a.

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?

No, they don't, here is the proof by contradiction.

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.

Question. How many divisors does a positive integer have?

Here is a picture of all divisors of integers in range [1, 500]

20

15

10

100 200 300 400 500

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

The number 2 is also special, it is the only even prime.

Theorem. There are an infinite number of primes

Proof. (by contradiction)

Assume otherwise, say, p1 , …, pn is a complete list of all primes.

Define

p p1 p2 … pn 1.

Since this number p is larger than all the pi , it cannot be prime.

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").

How would you find (or generate) primes?

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 .

Goldbach Conjecture (1742)


Prime numbers satisfy many strange and wonderful properties.

Observation:

6 3 3
7 5 2
8 5 3
9 7 2
10 7 3
18 11 7

What about 117 ? Can you represent it as sum of two primes?

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

This is not true for all primes, for example

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

a) 267 1 and 2257 1 are not primes


b) Mersenne missed p 61, 89, 107.

Definition: When 2 p 1 is prime it is said to be a Mersenne prime.

The largest known Mersenne prime is (2005):

225,964,951 1

Theorem. If 2 p 1 is prime, then p is prime.

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

which is easily proved by expanding the right hand side.


Therefore, if p is composite then x p 1 is composite, so is 2 p 1, since it's divisible by 2s 1.
Contradiction to our assumption that 2 p 1 is prime. QED.

Perfect numbers
Definition. An positive integer is a perfect number if it equals the sum of its proper divisors (not
including itself).

The first few perfect numbers are

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.

Question. Are they all even?

This question is much much harder.... It is not known if any odd perfect numbers exist.

All even perfect number are in the form

6=1+2+3 =2*3

28 = 1 + 2 + 3 + 4 + 5 + 6 +7 = 4 * 7

496 = 1 + 2 + 3 +... + 31 = 16 * 31

8128 = 1 + 2 + 3 +... + 127 = 64 * 127

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

Lecture 2 (out of seven)

Plan
1. Division Algorithm
2. The fundamental theorem of arithmetic
3. Counting the number of divisors

The Division Algorithm


The division algorithm is actually not an algorithm in the computer science sense of the word, but
rather an assertion that one can make sense out of integer division.

Theorem (The Division Algorithm)


Let b 0, and a arbitrary integers. Then there exist and unique integers q (the quotient) and r (the
remainder) such that

a q b r, where 0 r b.

Dividend = Quotient * Divisor + Remainder

Proof.

First we prove existence. Two cases:


a) b does divide a
b) b does not divide a

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

10 q 3 1, 4, 7, 10, 13, ...

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.

If a 0, choose q a, then a a b a b 1 0 is in the set. Observe, that


a b 1 0 since b cannot be equal 1. Why? Because of our assumption "b does not divide a."

Axiom (Well-Ordering Principle)


Every nonempty set of natural numbers contains a smallest element.

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

We prove that r 0 b (by contradiction)

Case 1. Let r 0 b

Substitute this into the above formula for r0

0 b a q0 b

Collect terms in b

a b q0 b q0 1 b

This implies that

b a
V. Adamchik 3

which contradicts to Case b) assumption that b a.

Case 2. Let r0 b 0.

Consider r0 b. It's positive r0 b 0 and also r0 b r0 .

Next we show that r0 b S

r0 b a q0 b b a q0 1 b S

Therefore, r0 b is in S and it is smaller than r0 . Contradiction to the minimality of r 0 .

It remains to prove that q and r are unique.

Suppose that

a q0 b r0
a q1 b r1

where 0 ri b and r0 r1 .

Substract one equation frpm another, we obtain

0 q0 b q1 b r0 r1

0 b q0 q1 r0 r1

b q0 q1 r1 r0

According to our assumption 0 r1 r0 b. Therefore,

0 b q0 q1 b

0 q0 q1 1

q0 q1

QED

The cancellation law. We have used an important property of the integers:


x y 0 implies x 0 or y 0.
It says that there are no nonzero zero-divisors in the integers.

Exercise. Where will the proof fail if you allow negative remainders?
V. Adamchik 21-127: Concepts of Mathematics

Exercise. Reformulate the above theorem when b 0 is not necessarily positive.

Here is a simple application of the Division Algorithm.

Lemma: Let p be prime. Then p a b implies that p a or p b.

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

Exercise. Argue that p r1 r2 if r1 r2 0. Note p is prime.

Application.We prove that 2 is irrational.

Proof. (by contradiction)

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

Contradiction, p and q have a common divisor 2. QED.

Exercise. Where will the proof fail if you try to prove that 4 is irrational?
V. Adamchik 5

The Fundamental Theorem of Arithmetic


One of the beautiful properties of the prime numbers is that every positive integer can be written as
a product of primes.

Theorem (The Fundamental Theorem of Arithmetic)


Let n 2 be an integer. Then there exist primes p1 , p2 , …, pk such that

n p1 p2 … pk .

If we require in addition that the sequence p1 , p2 , …, pk is ordered, then it is uniquely deter-


mined by n.

Example of prime factorization

300 = 2 * 2 * 3 * 5 * 5

Proof.
First existence. We use in induction on n.

The base case n 2 is obvious

Inductive Hypothesis: numbers up to n 1 can be writen as a product of primes.

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.

Uniqueness of the factorization. Suppose

n p1 p2 … pk q1 q2 … qs

where both sequences of primes are ordered.

Since p1 divides the second product, we must have p1 q i for some i. But then p1 q i.

By a similar argument, q 1 p j for some j.


V. Adamchik 21-127: Concepts of Mathematics

It follows from the order assumption that p 1 q 1 , so that

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

Observation. Count the number of positive divisors

2 has two divisors 1 and 2, 2 21

4 has three divisors 1,2 and 4, 4 22

12 has six divisors 1,2,3,4,6 and12, 12 22 3

300 has 18 divisors, 300 22 3 52

Each divisor of 300 22 3 52 must be in the form

2i 3j 5k

where 0 i 2, 0 j 1, 0 k 2, otherwise it won't divide 300. These will give us


3 2 3 18 choices. We use here the rule of product.

The rule of product:


Friday night out:
assuming that you can go to movies (5 choices) and then go to a party (3 choices), in how many
ways can you spend the evening?

Theorem. Integer

x p1 e1 p2 e2 ... pn em

has e1 1 e2 1 ... em 1 divisors.


V. Adamchik 1

Integer Divisibility
Victor Adamchik

Fall of 2005

Lecture 3 (out of seven)

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

where P and Q are some statements.

Direct Proofs

A direct proof is a flow of implications beginning with P and ending with Q.

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

Theorem. If x is integer and x2 is even, then x is even.


V. Adamchik 21-127: Concepts of Mathematics

x x2 is even x is even

Proof.

x x2 is even x is odd False

Given x2 2 k and x 2n 1. Combine them together

2
2k 2n 1

2k 4 n2 4n 1

2 k 2 n2 2n 1

Proofs by Contrapositive

In this method of proof we reverse the logical implication

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.

x, y x y is odd x y are odd

Proof.

either x y is even x y is even

Given x 2 k and y 2 n. Combine them together.

Proofs by Mathematical Induction

This proof technique can be stated as

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

the number of divisors is given by

e1 1 e2 1 ... em 1

Example. 72 has 12 divisors:

72 23 32

The positive divisors of an integer are pictured in a Hasse diagram as follows:


two divisors a and b are connected by a path going up if a is a divisor of b.
V. Adamchik 21-127: Concepts of Mathematics

Exercise. Draw a Hasse diagram for pk where p is prime.

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.

Integer x p1 e1 p2 e2 ... pn em has e1 1 e2 1 ... em 1 divisors.


Thus e1 1 e2 1 ... em 1 is odd or each factor is odd. Therefore, each ek is even. So x must
be a perfect square. Open lockers are those which are 1, 4, 9, 16, 25, ...

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

It is clear from the definition that


gcd a, b gcd a, b
1 gcd a, b min a, b .

Exercise. Prove that

gcd a, b gcd b, a b

Given a pair of numbers. Does a GCD always exist? Does it unique?

Let us prove it for positive integers

Theorem. a, b , !d , that is the GCD of a and 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.

First we prove that d exists, in other words that d a and d b.

By contradiction (on minimality of d).


Assume that d a. Using the division algorithm, a qd r where 0 r d

r a qd a q na mb 1 qn a qm b

We see that r S and r d. Contradiction, on minimality of d.

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

Corollary. gcd a, b n a m b, where n, m .

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

A useful lemma that is used in an algorithm for finding gcd.

Lemma. Let a bq r, then gcd a, b gcd b, r

Proof. Denote

d1 gcd a, b
d2 gcd b, r

Since d1 gcd a, b d1 r d1 divides both r and b therefore d1 d2 .


Conversely, since d2 gcd b, r d2 a d2 divides both a and b therefore d2 d1 .Hence,
d1 d2 . QED

Theorem (Euclidean Algorithm)


The algorithm computes a GCD of two positive integers a, b. We apply the division algorithm

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

The last non-zero remainder is GCD: gcd a, b rk

Proof. Let

S r1 , r2 , ..., rk

Set S contains a least element. This means that the above division will definitely terminate. Next.

gcd a, b gcd b, r1 gcd r1 , r2 ... gcd rk 1 , rk gcd rk , 0 rk

QED

Example. Let us trace the algorithm to find GCD(203, 91)

203 2 91 21
91 4 21 7
21 3 7 0

Question. When does the worst performance of the Euclidean Algorithm occur?

Let us run the algorithm for GCD(21, 13)

21 1 13 8
13 1 8 5
8 1 5 3
5 1 3 2
3 1 2 1
2 2 1 0

These are Fibonacci numbers (they usually denote as Fk )

1, 1, 2, 3, 5, 8, 13, 21, 34, ...

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. The Euclidean algorithm computes GCD Fk 1 , Fk in k 1 steps.


V. Adamchik 21-127: Concepts of Mathematics

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.

Here (phi) is the golden ratio defined by

5 1
2

as a solution of

x2 x 1 0
V. Adamchik 1

Integer Divisibility
Victor Adamchik

Fall of 2005

Lecture 4 (out of seven)

Plan
1. Extended Euclidean Algorithm
2. Continued Fractions

Extended Euclidean Algorithm


Theorem (Euclidean Algorithm)
The algorithm computes a GCD of two positive integers a, b by the following chain of divisions

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

The last non-zero remainder is GCD: gcd a, b rk

Exercise. Apply the Euclidean Algorithm to two real numbers. What will this procedure yield?

Theorem. gcd a, b n a m b, where n, m .

Question. How do you find such n, m that gcd a, b n a m b?

Let us run the algorithm to find GCD(203, 91)

203 2 91 21
91 4 21 7
21 3 7 0
V. Adamchik 21-127: Concepts of Mathematics

Next we reverse these equations. From the first equation we have

21 = 203 - 2 * 91

From the second equation we have

7 = 91 - 4 * 21

We substitute the first equation into the second

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

The EEA procceeds as follows. In accordance with the Euclidean algorithm

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

we build the matrix

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.

Example. Let us run the algorithm to find GCD(123, 45)


V. Adamchik 3

123 2 45 33
45 1 33 12
33 2 12 9
12 1 9 3
9 3 3 0

Here is the matrix for n and m:

123 1 0
45 0 1 2
33 1 2 1
12 1 3 2
9 3 8 1
3 4 11

Therefore,

GCD(123,45) = (-4) * 123 + 11*45

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

12*17 = 204 = 3*55 + 39


V. Adamchik 21-127: Concepts of Mathematics

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

gcd(5, 3) = 1 = 2*3 - 1*5

Multiply it by 52

52 = 104*3 - 52*5

Add and subtract 15 k, where k

52 104 5k 3 3k 52 5

We choose k in a such manner that

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

One more iteration

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

This expression is called a continued fraction for a rational number. Examples,

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

Continues fractions are used to solve quadratic equations

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

We repeat this substitution again

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

Lecture 5 (out of seven)

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 which integer solutions are sought.

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

What is the notion of solvable? What is the notion of an algorithm?

1930. Godel, Kleene, Turing developed the notion of computability.

1946. Turing invented Universal Turing Machine and discovered basic unsolvable problems

1970 Y. Matiyasevich proved that the Diophantine problem is unsolvable.

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.

Linear Diophantine Equations


Definition.
A linear Diophantine equation (in two variables x and y) is an equation

ax by c

with integer coefficients a, b, c to which we seek integer solutions.

It is not obvious that all such equations solvable. For example, the equation

2x 2y 1

does not have integer solutions.

Some linear Diophantine equations have finite number of solutions, for example

2x 4

and some have infinite number of solutions.

Thereom.
The linear equation a, b, c

ax by c

has an integer solution in x and y gcd a, b c


V. Adamchik 3

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

On the other hand

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

Then the pair x1 z and y1 z is the solution


QED.

How do you find a particular solution?


ax by c

By extended Euclidean algorithm we find gcd and such n and m that

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

Compare this with the original equation

ax by c

It follows that a particular solution is

n c m c
x0 ; y0
gcd a, b gcd a, b

Question. Are x0 and y0 integer?

Exercise. Find a particular solution of

56 x 72 y 40

Solution. Run the EEA to find GCD, n and m

GCD 56, 72 8 4 56 3 72

Then one of the solutions is

4 40 3 40
x0 ; y0
8 8

x0 20; y0 15

How do you find all solutions?


ax by c

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

Next we add and subtract a b k, where k

gcd a, b c a n c b m c a b k a b k

Collect terms with respect a and b

a nc bk b mc ak gcd a, b c

Divide this by gcd a, b


V. Adamchik 5

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

since x0 , y0 is a particular solution.

Therefore, all integers solutions are in the form

bk ak
x x0 y y0
gcd a, b gcd a, b

k 0, 1, 2, ...

Exercise. Find all integer solutions of

56 x 72 y 40

Solution. Run the EEA to find GCD, n and m

GCD 56, 72 8 4 56 3 72

All solutions are in the form

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

Positive solutions of LDE


In some applications it might required to find all positive solutions x, y .

We take a general solution

nc bk
x
gcd a, b gcd a, b

mc ak
y
gcd a, b gcd a, b

from which we get two inequalities

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

In the second case, there is an infinite number of solutions

nc b k 0

mc a k 0

Exercise. Determine the number of solutions in positive integers

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

which for our equation transforms to

2 117 7 k 0

1 117 4 k 0

This gives

2 117 117
k
7 4

There 4 such k, namely k 33, 32, 31, 30.

LDEs with three variables


Consider

3x 6y 5z 7

GCD 3, 6 x 2y 5z 7

Let

w x 2y

The equation becomes

3w 5z 7

Its general solution is

w 2 7 5k

z 1 7 3k

since
V. Adamchik 21-127: Concepts of Mathematics

GCD 3, 5 1 2 3 1 5

Next we find x and y

x 2y 14 5k

Since GCD 1, 2 14 5 k , the equation is solvable and the solution is

x 1 14 5k 2 l

y 0 14 5k 1 l

where l is another parameter. Here are all triple-solutions

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

Lecture 6 (out of seven)

Plan
1. The Money-Changing Problem
2. The Frobenius postage stamp problems

Review

Linear Diophantine Equations


The linear equation a, b, c

ax by c

has an integer solution in x and y gcd a, b c

All integers solutions are ( k ):

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

In the picture below, I plot two equations x y 1 and x y 1


V. Adamchik 21-127: Concepts of Mathematics

Plot x 1, x 1 , x, 5, 5 ;

-4 -2 2 4

-2

-4

LDEs with several variables


3x 4y 5z 6t 7

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

The solution will have two new parameters k2 and k3

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 .

The Money-Changing Problem


Problem. How many ways are there to make change for a $1 bill?

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.

Here are all possible choices to make change for a dime

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

Another approach is to use a recursive function.

Split the problem into two sub-problem


1. compute the number of changes with the largest coin
2. compute the number of changes without the largest coin

getChange amount coins maxIndex , coins, maxIndex


getChange amount, coins, maxIndex 1

The greedy algorithm


repeatedly take the largest coin that will fit and recursively give chnage for the remainder.
The algorithm gives you the smallest number of coins possible.
V. Adamchik 21-127: Concepts of Mathematics

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?

Given a, b . Which z can be expressed as a linear combination of a and b

z ax by

with positive integers x and y.

The Frobenius coin-exchange problem.


Given coins of k different denominations

0 d1 d2 ... dk with GCD d1 , ..., dk 1

Assuming an infinite supply of coins, we want to know what is the largest amount

d1 x1 d2 x2 ... dk xk N

that cannot be exchanged. This number is called the Frobenius number.

We will derive a formula for Frobenius numbers in case of two denominations.

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.

When the Diophantine equation has a unique positive solution?


V. Adamchik 5

x x0 b k

y y0 a k

k 0, 1, 2, ...

Among all x-solutions

..., x0 b, x0 , x0 b, ...

we choose one that

0 x b

What about y-solutions?

y 0

These are necessary conditions

Example.

3x 5y 11

All solutions are

nc bk mc ak
x and y
gcd a, b gcd a, b

or

x 22 5k and y 11 3k

Among all x solutions we choose such that

0 x b

Therefore,

0 22 5k 5 k 4

and the solution is

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

If z U z can be represented in the form z ax by

If z V z is not representable in the form z ax by z

What is Max V ?

x b 1 y 1

It follows that the maximum z that is not representable is

z b 1 a 1 b

This is the Frobenius number. QED.

The problem is algorithmically solved for 3 denominations and completely open for 4 and more
denominations. The problem is NP-hard. (Ramirez-Alfosin, 1996)

The Frobenius postage stamp problem.


The postal service of the rebuilt Iraq wants to issue 5 denominations of stamps (in whole numbers
of dinars) so that by using no more than 3 stamps on an envelope, citizens can pay for any postage
from 1 dinar to 36 dinars. How can this be done?

The set of stamps is 1, 4, 6, 14, 15.

1=1
2=1+1
3=1+1+1
...
19 = 14 + 4 +1
V. Adamchik 7

...
36 = 15 + 15 + 6

37 = ?

We like to generalize problems. Given stamps of k different denominations 1 d1 d2 ... dk

We want to know what is the smallest integer N that cannot be represented by

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

In the general case, it is NP-hard. (Shalit, 2002)

You might also like