Chicken McNugget Theorem – Bezout’s Identity
Given an unlimited number of 2 and 5 dollar bills, what all dollar values can be created? Clearly all multiples of 2 and 5 can be created, but they can also be combined to form many other values such as 7 (2 + 5), 13 (5 + 4 * 2) and so on. In fact, there are only a finite number of values that cannot be created in such a way by combining 2 and 5 dollar bills, and in general there are only finitely many values that cannot be created by combining hypothetical dollar bills and dollar bills where and are relatively prime. Equivalently, there are only finitely many values of such that the equation
(1)
has no solution for non-negative integers and . In this post I’ll characterize these values and prove the Chicken McNugget theorem for the largest such value.
Consider an arbitrary positive integer . To construct a solution to the equation
we consider both sides and see that
Now we need to find a value such that and leave the same reminder when divided by , or alternatively their difference is a multiple of . Consider the set of numbers {0, n, 2n, 3n, …, (m – 1)n}. Since and are relatively prime, this set is identical to {0, 1, 2, 3, …, (m – 1)} , so the first multiples of together with 0 cover all possible congruences . This means that no matter what is, we will always find exactly one in in the set {0, 1, 2, 3, …, (m – 1)} such that
Let’s call this specific value . Then we want to find some value of such that
Since the right hand side is a multiple of by our construction, it can be written as for some integer . The equation is reduced to
This shows that we can always find an integer that will constitute a solution to our equation along with . However, there is no guarantee that this value of will be non-negative, as was required for valid solutions. This means that any value of such that
is negative will not yield a valid solution to our original problem.
Rearranging and going back to our definition of , we see that the values of that yield no solution can be written as , where is negative and is in the set {1, 2, 3, …, {m – 1)} ( cannot be 0 because then we’d be left with which is negative). Using different variables, we can state that our original equation has no solution if and only if can be written as , where and are positive integers and . The maximum such value will be obtained by maximizing and minimizing . So and , yielding
(2)
which is the statement of the Chicken McNugget theorem.
Going back to our original example, we see that the largest value that cannot be attained using 2 and 5 dollar bills is .
Using another example, suppose you are at a store buying bananas, and bananas come in bunches of 3 or 5. To find the number of bananas that are impossible to obtain, we let and and apply the result above, considering multiples of 3 from 1 * 3 to (5 – 1) * 3, subtracting multiples of 5 from them and stopping before we reach a negative value. We cannot subtract any multiple of 5 from 1 * 3 without reaching a negative value so we move on. 2 * 3 yields one value, . 3 * 3 also yields one value, . 4 * 3 yields two values, and . Thus, the only numbers of bananas that are impossible to obtain are 1, 2, 4 and 7, and every number larger than 7 is possible to obtain (at least until the store runs out of them!)
While deriving the solution, we also noted that the only thing that is stopping a solution from existing for the equation (1) for all integers is our restriction that and have to be non-negative. Otherwise we could simply plug our value for into the equation for without worring about it being negative. This means that if we allow and to be negative, our original equation has solutions for every integer (not just every non-negative integer , as we can find solutions for negative by finding solutions for positive and simply replacing and with and ). We can also extend this to pairs and that are not relatively prime.
We now go back to the equation (1), but this time allowing and to be any integers, to be any integer and and to share common factor(s). Clearly, the left hand side is divisible by so the must also be. Then we can write as for some integer . Dividing both sides by , we get
(3)
Since and are relatively prime (we have removed any of their common prime factors when dividing by their gcd), this new equation has solution for all y. This means that our original x can be written as for any integer , or that our original equation has solutions for any that is a multiple of , a result known as Bezout’s Identity.
One thought on “Chicken McNugget Theorem – Bezout’s Identity”
Kudos for a simple and wonderful explanation of Bezout’s Identity