# Patterns in the Last Digits of the Positive Powers of Five

The positive powers of five — 5, 25, 125, 625, 3125, 15625, … — have a compact, repeating pattern in their ending m digits, in the powers of five from 5m on. For example: starting with 5, their last digit is always 5; starting with 25, their last two digits are always 25; starting with 125, their last three digits alternate between 125 and 625. These cycles come in lengths of powers of two.

I will show you why these cycles exist, how they are expressed mathematically, and how to visualize them.

(This article is the companion article to “Patterns in the Last Digits of the Positive Powers of Two”. It describes the digit patterns in the negative powers of two, indirectly, since positive powers of five look like negative powers of two.)

## Cycles in the Last One to Four Digits

You can use modular arithmetic to show the repeating digit cycles of the positive powers of five. You can find the last m digits of a positive power by computing its common residue mod 10m. You can find the last m digits of a sequence of powers by computing them incrementally, mod 10m. The cycle restarts when you get a result you’ve already seen.

### Last Digit

Starting with 5, the last digit repeats in a cycle of period one: 5. You show it with incremental calculations mod 10:

1. 2. In other words, every positive power of five ends in 5.

### Last Two Digits

Starting with 52, the last two digits repeat in a cycle of period one: 25. You show it with incremental calculations mod 102:

1. 2. 3. ### Last Three Digits

Starting with 53, the last three digits repeat in a cycle of period two: 125, 625. You show it with incremental calculations mod 103:

1. 2. 3. 4. 5. ### Last Four Digits

Starting with 54, the last four digits repeat in a cycle of period four: 0625, 3125, 5625, 8125. You show it with incremental calculations mod 104:

1. 2. 3. 4. 5. 6. 7. 8. Whenever the residue is less than m digits, it is implicitly padded out with leading zeros. For example, the last 4 digits of 58 = 390625 are 0625.

## Cycles in the Last m Digits

If you continue this process, you’ll see that the period doubles for each additional ending digit; I did the calculations through ten ending digits:

Cycle Length for Number of Ending Digits (1 to 10)
m Period Starts with
1 1 51
2 1 52
3 2 53
4 4 54
5 8 55
6 16 56
7 32 57
8 64 58
9 128 59
10 256 510

This table implies that the ending m digits of the positive powers of five cycle with period 2m-2, m ≥ 2, starting at 5m. (The proof is here.)

Powers of five with exponents that are congruent mod 2m-2 are themselves congruent mod 10m. That is, 5i and 5i+(2m-2)·k, i ≥ m, k ≥ 0, end with the same m digits.

## Visualizing the Nesting of Cycles

The cycles in m digit, m-1 digit, m-2 digit, …, 1-digit endings can be viewed as nested, even though their starting points are staggered. You just have shift the starting points of the lesser digit cycles to make them coincide. For example, each copy of the length 4 cycle of four digit endings has within it two copies of the length 2 cycle of three digit endings; each copy of the length 2 cycle of three digit endings has within it 2 copies of the length 1 cycle of two digit endings.

This diagram shows the nesting by shading every other occurrence of a cycle (the millions place is fully shaded, because only one cycle of the last seven digits is shown):

Not surprisingly, the nested powers of two in this pattern make it look similar to the pattern in consecutive binary integers.

### Binary Tree

Another way to show the nesting of powers of two is with a binary tree. Here is a tree showing the ending 1-5 digits:

Each level contains the ending digits for a given cycle, from the last digit (the root, or first level) to the eight 5 digit endings (the leaves, or fifth level). Starting with the second level, each m digit ending is the suffix of two m+1 digit endings.

Here’s the same tree, except labeled with the smallest power of five corresponding to the ending digits:

Each level from level 2 down includes the endings for 5m through 5(m+2m-2-1).

Notice two interesting things that become apparent with the binary tree representations:

• The starting digits of each pair of children, for m ≥ 3, differ by 5. For example, 3125 and 8125 on level 4 (digits 3 and 8).
• The exponents of each pair of children, for m ≥ 3, differ by 2m-3. For example, 55 and 57 on level 4.

(For more details, see my article “Ending Digits of Powers of Five Form a Binary Tree”.)

## Exploring Ending Digits with PARI/GP

You can use PARI/GP to explore the cycles in the ending digits; here are two examples:

• Print the first 20 positive powers of five:
? for(i=1,20,print("5^",i,": ",5^i))
5^1: 5
5^2: 25
5^3: 125
5^4: 625
5^5: 3125
5^6: 15625
5^7: 78125
5^8: 390625
5^9: 1953125
5^10: 9765625
5^11: 48828125
5^12: 244140625
5^13: 1220703125
5^14: 6103515625
5^15: 30517578125
5^16: 152587890625
5^17: 762939453125
5^18: 3814697265625
5^19: 19073486328125
5^20: 95367431640625

• Show the cycle in the last m (in this case 5) digits:
? m=5; for(i=1,2^(m-2)+m,print("5^",i," mod 10^",m": ",5^i%10^m))
5^1 mod 10^5: 5
5^2 mod 10^5: 25
5^3 mod 10^5: 125
5^4 mod 10^5: 625
5^5 mod 10^5: 3125
5^6 mod 10^5: 15625
5^7 mod 10^5: 78125
5^8 mod 10^5: 90625
5^9 mod 10^5: 53125
5^10 mod 10^5: 65625
5^11 mod 10^5: 28125
5^12 mod 10^5: 40625
5^13 mod 10^5: 3125


(The leading 0 of 3125 is not printed.) ## One comment 