Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
In this tutorial, we’ll study how to compute the unit digit in an exponentiation operation.
The operation of exponentiation or “raising to a power” is a non-commutative binary operation that affects two numbers:
We can indicate the operation of exponentiation of by
, alternatively as:
The first of these three methods is common in programming languages such as Java or Kotlin. The second is the one most frequently used in mathematics. At the same time, the last one emphasizes the underlying nature of the operation. In fact, we can always write any exponentiation as a repeated multiplication of the base with itself, with the multiplication happening as many times as indicated by the exponent.
While the operation of exponentiation is defined for larger sets than , for the rest of this article, we’ll only treat cases where both the base and the exponent are natural numbers. Thus, we always assume that
. We also assume that if the base is zero, the exponent cannot be zero since that would lead to the form
that can be interpreted differently according to the context.
First, we must consider an alternative way to express a natural number. When we work in base 10, we can always express any number as the sum of products between the powers of 10 and the unit digits. Let us take, as an example, the number 3456 in base ten. We can express it as:
The polynomial decomposition of 3456, according to the powers of ten, would then be . Similarly, the number 789, as a second example, we can decompose into a polynomial of the powers of ten as
. More generally, we can express any number in any numerical base as a polynomial of the powers of that base multiplied by some coefficients.
Let’s think of a number as a polynomial of the numerical base and its powers. We can then think of exponentiation of that number as the operation of raising that polynomial to some power. If, for example, we are calculating , then this is equivalent to calculating
because the terms inside the bracket correspond to the original number. For this reason, we can also rewrite the previous expression as
. If we then expand the brackets according to the rules for the multiplication of polynomials, we can rewrite it as:
(1)
In doing so, we can now notice how, if we multiply all of the terms within each pair of monomials, we will always obtain a new monomial that is at least as high, in degree, as the greatest degree of the monomials being multiplied. If, for example, we want to multiply the first pair of monomials, , we will end up producing a product between a number and the fourth power of ten:
(2)
Notice how has a greater degree (i.e., a greater exponent) than each of the monomials being multiplied. If we instead multiply the last pair of monomials, sorted in decreasing order of degree, we will produce a product between some numbers and
:
(3)
Notice that, in this case, this is the only term that contains . And here is an important insight that we can formulate: for any exponentiation of any base to any power, the only monomials that affect the value of the unit digit of the resulting power are those corresponding to the unit digit of the base number. For this reason, if we wanted to express the final result of the polynomial multiplication as a whole number, its unit digit would be the one that corresponds to the unit digit of this last multiplication (and, therefore, of the exponentiation).
Therefore, if all we had wanted to know was the last digit of the power , we could have:
Since, by constructing the problem, we aren’t interested in any other digit other than the last one, this procedure is sufficient to solve the task at hand.
More generally, if we want to obtain the unit digit of a number , all we need to do is to:
This latter digit will then be the unit digit of the base raised to the power of
.
In this article, we studied how to compute the unit digit in exponentiation.