The Puzzle
A woman goes to the market with a basket full of eggs. On her way, a horse bumps into her, causing her to drop the basket and break all the eggs. The horse's owner feels guilty and asks how many eggs she had so he can compensate her. She replies:
"I don't remember the exact number of eggs, but I do remember this:
- When I tried to group the eggs two at a time, there was one egg left over.
- The same happened when I grouped them three at a time, four at a time, five at a time, and six at a time—there was always one egg left over.
- However, when I grouped them seven at a time, there were no eggs left over."
What is the smallest number of eggs she could have had?
Explanation
We have to search for a number that is divisible by seven but always leaves a remainder of one when divided by
It is fairly easy to find a number not divisible by any of the integers
Keep in mind that solving the puzzle is straightforward, but I’m more interested in a formal approach. Specifically, I’m looking for a method to determine whether a general solution exists, along with a formula or algorithmic approach to compute it.
Naturally, I realize that the abstract mathematical questions I posed above are not the first questions which come to mind when one encounters this puzzle, so I will start by presenting the direct easy solution first.
A naive approach
Consider
An educated approach
The idea is simple: compute the least common multiple
of the integers
The Mathematics
Let's start by writing the idea above formally. The least common multiple of these integers is:
Using a congruence relation, we can write a general form for the solution: The solution - let's call it
The first multiple of
A trick using congruence relations
There is a simple trick that makes use of congruence relations.
This trick makes the arithmetic - and therefore the process of trial and error - for finding
Consider the following equivalent statements:
The first n which makes
Note These statements are equivalent because congruence relations are compatible with algebraic structures. In this case the algebraic structure is the integer ring
, with the conventional addition and multiplication.
The Chinese Remainder Theorem
Theorem
Given a system of
Furthermore, if
This is one of multiple possible statements of the theorem. It is of course a modern formulation but the theorem originates from 5th century china, in a book on mathematics. It appeared as conjecture without proof or algorithm.
Great… how does this help us in actually finding the solution? Well, the theorem has a proof by construction. This means that we can prove the theorem by constructing a solution for a general form of the puzzle above.
Proof of existence by construction
Let
A well known result in number theory says that if two integers are coprime - as is the case with
For any other index
This is all we need to construct an integer
and check for any
Since we already know that
which proves the statement of the theorem.
remarks
In the proof above we have constructed a solution
With that in mind, consider again the statement:
Write:
Without loss of generality we can write this as:
Note Note that 1 is the greatest common divisor of
and and the equation above is called Bézout's identity.
The factors
Bézout's identity and the Euclidean algorithm warrant an article by themselves and are therefore beyond the scope of this post.")}}
Application of the theorem
First we need to formulate the puzzle in a way that is compatible with the theorem. We could write:
We can improve on this by using the least common multiple of these integers,
where
Now it only remains to compute Bézout's coefficients for the identity:
As mentioned before, those coefficients are computed from the Euclidean algorithm of division. In this case we have:
The solution