An interesting calculator discovery and the result of a 12-hour drive
I recently drove 12 hours from our home in Santa Fe to our beach spot in Mexico while Sonya had numerous virtual meetings and phone calls en route. This meant that I was not able to listen to music nor any of my podcasts as I do not like to drive with earphones in use. No matter, I had come across something interesting a few days prior and I spent most of the entire drive focused on it. I wrote a draft of this post in my notebook the next morning so I wouldn’t forget it.
A few days prior I was working on something and noticed the following. Suppose you started with the number 2 and then squared it. You get the number 4. Squared again, 8. Then 16, then 32, and so on. What I noticed was the last digit of each subsequent squaring, written down as {2, 4, 8, 6, 2}. After five such squares, that is after reaching , we end up back at 2. From there the cycle repeats. Here are the various powers of 2 and the last digit of each
This is not unique to the number 2. Any number raised to increasing integer powers will show a cycle. What is interesting is that there will never be a cycle length larger than 5 when looking at the frequency of occurrence of the last digit. Shown in the next table are the various cycles that may appear.
We see that not all cycles are of length 5. For 1, 5, and 6, in fact, the cycle length is only 1. The numbers 4 and 9 have cycles of length 2. But there is no cycle greater than length five. Why is that? And why is it that no matter what the starting number is, we will reach the same last digit after raising any number to a fifth power?
This applies to numbers of more than a single digit, of course. Suppose we started with the number 83. In successive powers we have 83, 6,889, 571,787, 47,458,321, and 3,939,040,643. The cycle of last digits is {3, 9, 7, 1, 3}, the same as for the digit 3, itself. No matter how large of a number we start with, after raising it to successive powers the last digit will cycle back around to the last digit of the number with which we started, following one of the cycles appearing in the table above for single digits. If it is not clear why this is so, think about what a multiple digit number is. It is a single digit, plus another digit multiplied by 10, plus another digit multiplied by 100, and so on. Consider a two-digit number where and are single digits. Squaring it gives
The first two terms on the right end in 0 so the last digit will be determined by the last digit of .
Thus the questions remain, why are there no cycles greater than 5 and why, no matter what, when we raise any number to the power of 5 do we get a number whose last digit is the same as the number with which we began?
When talking about cycles that appear in numbers there is a good chance that we will be making use of modular arithmetic, a part of mathematics based on wrap-around behavior. If you are unfamiliar with this subject, think of how most Americans keep time using a 12-hour clock. Let represent the number of hours that have passed since midnight. We would say that the current hour is mod 12, that is, it is the reminder after dividing by 12. If n = 6 then 12 goes into 6 zero times, with a remainder of 6. So it is 6 AM. If n = 14 then 12 goes into 14 once with a remainder of 2. It’s 2 PM. We say the hour of the day is based on a modular-12 system.
Modular arithmetic will come into play in our explanation for the questions raised at the end of the last section. We will use the concept of congruence between numbers based on some modular value. Two values and are said to be congruent based on some modular value if the difference between the two values is evenly divisible by . This is written as
Note the three-lined equivalence symbol being used and the ‘(mod m)’. The parentheses around the latter indicate that it applies to the whole equation, both the left and right sides. The notation is not too complicated and means nothing more than the difference is evenly divisible by , i.e. for some integer . Another way mathematicians write “is evenly divisible by” is the following notation,
Keep in mind the ‘(mod m)’ type of notation in what follows. A common temptation is to think that the statement is a shorthand way to say, “ is the remainder when is divided by .” However, this is not always the case. Here are a few examples to drive home the meaning of the congruence relation.
because is evenly divisible by 4. Note that is definitely not the remainder of .
because is evenly divisible by 16.
An interesting theorem involving modular arithmetic and prime numbers was introduced by Fermat and is known as Fermat’s Little Theorem in deference to his more famous Last Theorem.
Recall that a prime number is one that is only divisible by itself and the number 1. Fermat’s Little Theorem states that for any prime number and any number not divisible by that
This theorem is essential to answering our questions so it is worth showing a proof. Also, it leads to a generalization due to Euler that will more directly answer our questions.
To prove Fermat’s Little Theorem, start by creating a set of numbers from 1 to . Call this set ,
There are a total of elements of , all less than , and so it should be obvious that for any member of , written as , that mod = . So every member of is unique and every member has a unique congruence modulo , that is, a unique remainder mod , namely itself. Next form a new set where we multiply every member of by . This new set is
Every element of this new set also has a unique congruence modulo . To show this, assume that two members of had the same congruence relationship modulo . That is,
for some integer q. This implies that and for integers . If we subtract these we get
The right-hand side is clearly divisible by p and this means that
The integers and are both less than because of how the set was constructed, hence their difference must also be less than . This fact, combined with the assertion at the beginning that is not divisible by , means that the only way the above congruence relation can hold true is if , proving the congruence uniqueness for the set .
We have just shown that all of the congruences of the set are unique. Each one is also less than by definition of taking the modulus with , so there is a one-to-one correspondence with the congruences of the set with those of the set . The congruences modulo of the set are a permutation of those of . However, we can multiply all these congruences to see that
and finally, we can divide each side by to get the result, Fermat’s Little Theorem,
Euler extended Fermat’s Little Theorem to non-prime values of . Suppose is any integer and that and are coprime. This just means that the greatest common divisor of either number is 1, written gcd() = 1. Then in general Fermat’s Little Theorem does not hold. We already see a problem with the set . Some of those elements may have the same congruence relations modulo . Instead, we form a new set containing only the numbers 1 to that are coprime to . For example, if our set would look like this,
Those are the only numbers in the range 1 to 12 that are coprime to 12. (Numbers are not considered coprime to themselves.) The number of elements of is denoted and is called Euler’s totient function. is the count of numbers less than that are coprime to . There is no general function to write down in order to compute but it has been tabulated for numerous values in various tables. Here we show just a few examples.
Note in particular the last row. For any prime number we have and you should see that Fermat’s Little Theorem is just a special case of Euler’s Theorem when is a prime number. Another property of the totient function is that for any two prime numbers and , .
Let’s return to the new set . As for the case in proving Fermat’s Little Theorem, each of these numbers is less than and the congruences are all unique. Again we form a new set where we multiply each member of by the number .
If and for some then this implies that divides , but and are coprime so we know does not divide . Thus can only divide which can only happen if . Therefore, the set is a permutation of all the congruences contained in modulo , just as what we found for the sets used to prove Fermat’s Little Theorem. As before, we now multiply all the congruences to see that
and upon dividing each side by the multiplication terms, we arrive at Euler’s Theorem for numbers and coprime,
As a corollary we can multiply both sides by to get the relationship
So how does Euler’s Theorem help answer the question of why there is no cycle length greater than 5 for examining the last digit when raising numbers to successive powers? We’re getting there.
Suppose where both and are prime numbers and neither one divides . Then we will claim that
holds for all values of , not just those coprime to .
If then it is obviously true. If is not a multiple of either or then it is true by Euler’s Theorem. All that is left is to consider the case where is a multiple of either or . Suppose for some integer . Then
means that
i.e. that divides the terms in brackets. We can clearly divide from both terms in the brackets so all that is left is to show the divides the terms
Note that that by our assumptions ( and both prime numbers) that , and . By Euler’s Theorem we have that
or
By the multiplicative property of modular arithmetic (see appendix) we can raise the power of and the congruence relation will still hold, so
where we made use of the fact that for prime numbers.
To restate, for any number and where and are both prime,
Finally, to address our questions let and , so that . We know that from the previous chart. By Euler’s Theorem then, for any number ,
and
The fact that is evenly divisible by 10 means that any number that has been raised to the fifth power ends in a digit that is the same as the last digit of , answering one of our questions. We also know from earlier discussions that once a number ends in the same digit as the last digit of the number with which we began, that the cycle starts again. There can be no cycle of length greater than 5.
The multiplicative property of modular arithmetic states that if and then
To see this, note that , . Then
Recent Comments