In this blog series, I am exploring a few of my favourite algorithms in mathematics.
Last week, we looked at an algorithm that allowed us to calculate the greatest common divisor of two numbers using halving and subtraction. This week, I want to dive into the idea of divisibility rules.
Some numbers have easy divisibility rules. For example, a number is divisible by 2 if it ends in a 0, 2, 4, 6, or 8. It doesn’t take much mental energy to confirm that is indeed divisible by 2. Similarly, a number is divisible by 5 if it ends in a 0 or 5. So clearly is not divisible by 5.
But what about 3? Is divisible by 3? Perhaps numbers that are divisible by 3 have a nice pattern, like the numbers that are divisible by 2 or 5. If we start at 3, and list all numbers divisible by 3, we get:
This list is not good news. Notice that these numbers end in every possible digit! So is divisible by 3? Well it ends in a 5, let’s consider our options.
15 is divisible by 3 and ends in a 5. But 25 also ends in a 5 and clearly 25 is not divisible by 3. Ending in a 5 is not enough to determine divisibility by 3. So all we can say is maybe, maybe divisible by 3…
This illustrates a very crucial fact: to determine divisibility by 3, we need to look beyond the last digit of the number. Indeed, in the divisibility rule for 3, all the digits in the number will play a role.
The first step is to forget about the place value of each of these digits and simply treat them as individual numbers. Next, we add up all these numbers. For , this gives us:
Now we ask a surprising question, is this new number divisible by 3? For sure! 24 is on our list of numbers divisible by 3. So the rule says, since this new number is divisible by 3, the original number is divisible by 3. Done.
Don’t believe me? Calculate . You will get back our number:
Let’s try a smaller number. Clearly is divisible by 3 since . If we use our rule, we get:
Since 12 is divisible by 3, is also divisible by 3.
We can even apply this rule multiple times. Consider the gigantic number . Is this number divisible by 3?
First, we add all the digits:
Now 54 is not on our list. We could try some mental math to determine if 54 is or is not divisible by 3, but instead, we can just add the digits again!
9 is on our list and we are done, is divisible by 3.
To see why this works, consider . If we apply our algorithm, we get
This means should divisible by 3 according to our rule.
Now let’s unpack what we did. The first 2 actually stands for 2 groups of 1000, the 7 stands for 7 groups of 100, the 8 stands for 8 groups of 10, and the last 4 stands for 4. We could write this as:
Next, we break off a 1 from each of these powers of 10. This give us:
Finally, we can use the distributive property and get:
Now won’t affect our final answer because 999 is already divisible by 3. Similarly, and also wont affect our final answer. If we discard all these terms, we get:
This is just adding up all the digits, exactly what we were doing! In essence, by only using the digit and not the place value, we are disregarding either a 9, or a 99, or a 999. But these numbers are already divisible by 3 and so disregarding them is totally fine.
As a fun extension, this rule also works for divisibility by 9. So, our first number is not divisible by 9, since 24 is not divisible by 9. However, our gigantic number, is divisible by 9, since 54 is divisible by 9.
I love both of these divisibility rules because they employ such simple mathematical operations. Trying to do long division on a number like would be a very tedious process. But anyone can add up the digits of a number. And you could even have fun doing it!