Sub topic 3
Cyclicity: how unit digits repeat in powers
This chapter assumes you can read the unit digit of a number as its remainder mod 10, and that you can multiply unit digits as in the previous chapters. You should also know the laws of exponents and how to divide with a remainder. Cyclicity is the tool that turns "unit digit of 7^123" from an impossible calculation into a ten-second one.
The idea: unit digits of powers repeat
Take the powers of 2 and write only the unit digit of each:
| n | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 2^n | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 |
| unit digit | 2 | 4 | 8 | 6 | 2 | 4 | 8 | 6 |
The digits 2, 4, 8, 6 repeat forever. The length of the repeating block is the cyclicity of the digit. For 2 it is 4.
The repetition is guaranteed, not a coincidence. The unit digit of a^(n+1) is the unit digit of (unit digit of a^n) × (unit digit of a). The next digit depends only on the current digit and the base's digit. There are only ten possible digits, so some digit must eventually come back. From that point the sequence repeats exactly.
Only the unit digit of the base matters. 12^n, 32^n and 1002^n all end in the same digits as 2^n, because multiplying numbers only changes the unit digit through their unit digits.
The cycle for every digit
Work out each base digit once and memorise the result.
| Base digit | Cycle (n = 1, 2, 3, ...) | Cycle length |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 1 | 1 |
| 5 | 5 | 1 |
| 6 | 6 | 1 |
| 4 | 4, 6 | 2 |
| 9 | 9, 1 | 2 |
| 2 | 2, 4, 8, 6 | 4 |
| 3 | 3, 9, 7, 1 | 4 |
| 7 | 7, 9, 3, 1 | 4 |
| 8 | 8, 4, 2, 6 | 4 |
You can group these by length:
- Digits 0, 1, 5 and 6 never change. Any positive power of a number ending in 5 ends in 5, and any positive power of a number ending in 6 ends in 6.
- Digits 4 and 9 alternate. An odd exponent gives 4 (or 9). An even exponent gives 6 (or 1).
- Digits 2, 3, 7 and 8 need the full cycle of 4.
You can regenerate any row in a few seconds if you forget it. Multiply the digit by the base digit repeatedly and keep only the unit digit.
Using the cycle: the three-step method
Suppose you want the unit digit of a^n for a large n.
- Take the unit digit of a. Ignore everything else about the base.
- Find the remainder of n when divided by the cycle length. If the remainder is 0, use the last position of the cycle.
- Read the digit at that position in the cycle.
Example 1: 7^123. The cycle for 7 is 7, 9, 3, 1, with length 4. We have 123 = 4 × 30 + 3, so the remainder is 3. The third entry is 3. The unit digit is 3.
Example 2: 2^2026. The cycle is 2, 4, 8, 6. We have 2026 = 4 × 506 + 2, so the remainder is 2. The second entry is 4. The unit digit is 4.
Example 3: 18^100. The base digit is 8, with cycle 8, 4, 2, 6. We have 100 = 4 × 25, so the remainder is 0. A remainder of 0 means the last position, which is 6. The unit digit is 6.
You can check each answer in Python with the three-argument pow, which computes the power modulo 10 directly:
print(pow(7, 123, 10)) # 3
print(pow(2, 2026, 10)) # 4
print(pow(18, 100, 10)) # 6A single table keyed on n mod 4
Memorising two different cycle lengths adds a chance of error under time pressure. There is a simpler rule. Every cycle length (1, 2 or 4) divides 4, so the cycle of every digit repeats every 4 steps. For a positive exponent n you can always reduce n mod 4 and use this table.
| Base digit | n mod 4 = 1 | n mod 4 = 2 | n mod 4 = 3 | n mod 4 = 0 |
|---|---|---|---|---|
| 2 | 2 | 4 | 8 | 6 |
| 3 | 3 | 9 | 7 | 1 |
| 4 | 4 | 6 | 4 | 6 |
| 7 | 7 | 9 | 3 | 1 |
| 8 | 8 | 4 | 2 | 6 |
| 9 | 9 | 1 | 9 | 1 |
Digits 0, 1, 5 and 6 give 0, 1, 5 and 6 in every column. The column for remainder 0 is the "fourth position" of the cycle. This table explains why textbooks often say "divide the exponent by 4" for every base.
The rule behind this is that for any digit coprime to 10 (1, 3, 7, 9) the powers return to 1 after 4 steps at most. Number theory expresses this with Euler's totient, φ(10) = 4, but you do not need the theory to use the table.
Code that implements the method
This function follows the cycle table exactly. It is useful for checking your hand work on practice questions.
def unit_digit_power(a, n):
if n == 0:
return 1
d = a % 10
if d in (0, 1, 5, 6):
return d
cycles = {2: [2, 4, 8, 6], 3: [3, 9, 7, 1], 4: [4, 6],
7: [7, 9, 3, 1], 8: [8, 4, 2, 6], 9: [9, 1]}
cycle = cycles[d]
return cycle[(n - 1) % len(cycle)]
print(unit_digit_power(7, 123)) _digit_power(18, 100)) # 6
# Cross-check against pow for many bases and exponents.
for a in range(1, 40):
for n in range(1, 60):
assert unit_digit_power(a, n) == pow(a, n, 10)
print("alled")The expression cycle[(n - 1) % len(cycle)] handles the "remainder 0 means last position" rule automatically. Subtracting 1 shifts the exponent so that n = 1 maps to index 0. The remainder 0 case then lands on the last index, which is works where a plain n % len(cycle)` would not.
Combining cycles with unit-digit arithmetic
Real questions usually involve more than one power. Find each unit digit separately, then combine them with the sum, difference or product rules from the previous chapter.
Example 4: the unit digit of 3^45 × 7^38.
- 3^45: 45 mod 4 = 1, so the digit is 3.
- 7^38: 38 mod 4 = 2, so the digit is 9.
- The product of the digits is 3 × 9 = 27, which ends in 7.
Example 5: the unit digit of 19^47 + 22^83.
- 19^47: the base digit is 9 and 47 is odd, so the digit is 9.
- 22^83: the base digit is 2 and 83 mod 4 = 3, so the digit is 8.
- The sum is 9 + 8 = 17, which ends in 7.
Common errors
- Using the last digit of the exponent. Only the remainder mod 4 matters, and that depends on the last two digits of n. For 3^2027, 2027 mod 4 = 3 (since 27 mod 4 = 3), so the digit is 7. Looking only at the final 7 and treating it as "remainder 7" gives nonsense.
- Treating remainder 0 as the first position. A remainder of 0 means a complete cycle has finished, so you land on the last entry. 3^100 ends in 1, not 3.
- Using the whole base. 1234^n depends only on the digit 4. Do not multiply out any part of 1234.
- Forgetting the exponent 0. For a ≠ 0, a^0 = 1 whatever the cycle says. The cycle table starts at n = 1.
- Subtracting unit digits blindly. If the unit digit of the first term is smaller than the second, add 10 before subtracting. For 6^50 − 9^21, the digits are 6 and 9, and (16 − 9) = 7 is the unit digit, provided the first number is larger. Here 6^50 is much larger than 9^21, so the borrow is legitimate.
When the method breaks
The cycle method covers positive integer exponents. Two cases need extra care.
- Negative or fractional exponents do not produce integers, so "unit digit" has no meaning.
- The exponent is itself a power, such as 3^(4^5). Then you must reduce the exponent mod 4 by working out its own structure first. That is the topic of the power-tower chapter, so leave it for later.
Exercise
Find the unit digit of 19^47 + 22^83 − 4^101.
Show answer
19^47 ends in 9 (base digit 9, odd exponent). 22^83 ends in 8 (83 mod 4 = 3, third entry of 2, 4, 8, 6). 4^101 ends in 4 (odd exponent). The unit digit of the expression is the unit digit of 9 + 8 − 4 = 13, which is 3. The sum of the first two terms is far larger than 4^101's contribution would require borrowing from, so no borrow issue arises at the unit position. The answer is 3.
Exercise
What is the unit digit of 2^n when n = 1999, and for which values of n does 3^n end in 1?
Show answer
1999 mod 4 = 3 (since 99 mod 4 = 3), so 2^1999 ends in the third entry of 2, 4, 8, 6, which is 8. For 3^n, the cycle 3, 9, 7, 1 reaches 1 at the fourth position, so 3^n ends in 1 exactly when n is a multiple of 4.
Exercise
A student claims that 8^2026 ends in 8 because "the exponent ends in 6 and 8 times 6 is 48". Find the actual unit digit and name the mistake.
Show answer
The cycle for 8 is 8, 4, 2, 6. We have 2026 mod 4 = 2, so the unit digit is 4. The student used the last digit of the exponent as if it were a multiplier. The exponent only matters through its remainder mod 4, which depends on its last two digits.