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 5^{m} 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 10^{m}. You can find the last m digits of a *sequence* of powers by computing them incrementally, mod 10^{m}. 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:

- …

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

### Last Two Digits

Starting with 5^{2}, the last two digits repeat in a cycle of period one: **25**. You show it with incremental calculations mod 10^{2}:

- …

### Last Three Digits

Starting with 5^{3}, the last three digits repeat in a cycle of period two: **125, 625**. You show it with incremental calculations mod 10^{3}:

- …

### Last Four Digits

Starting with 5^{4}, the last four digits repeat in a cycle of period four: **0625, 3125, 5625, 8125**. You show it with incremental calculations mod 10^{4}:

- …

Whenever the residue is less than m digits, it is implicitly padded out with leading zeros. For example, the last 4 digits of 5^{8} = 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:

m | Period | Starts with |
---|---|---|

1 | 1 | 5^{1} |

2 | 1 | 5^{2} |

3 | 2 | 5^{3} |

4 | 4 | 5^{4} |

5 | 8 | 5^{5} |

6 | 16 | 5^{6} |

7 | 32 | 5^{7} |

8 | 64 | 5^{8} |

9 | 128 | 5^{9} |

10 | 256 | 5^{10} |

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

Powers of five with exponents that are congruent mod 2^{m-2} are themselves congruent mod 10^{m}. That is, 5^{i} and 5^{i+(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 5^{m} 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 2**. For example, 5^{m-3}^{5}and 5^{7}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

(Cookies must be enabled to leave a comment...it reduces spam.)