Sub topic 2
Unit digit of power towers
This chapter assumes you know place value, prime factorisation, the laws of exponents, division with remainders, and the meaning of n!. Every method here works with remainders. The unit digit of a number is its remainder mod 10, and its last two digits are its remainder mod 100.
Unit digit of power towers
A power tower such as a^(b^c) has an exponent that is itself a power. Evaluate the top exponent first, then reduce it. The unit digit of a^k repeats in cycles of length 1, 2 or 4, so only the exponent's position in the cycle matters.
For 3^(4^5), compute 4^5 = 1024. Since 1024 mod 4 = 0, the exponent sits at position 4 of the cycle 3, 9, 7, 1, which gives unit digit 1.
def tower_unit_digit(a, b, c):
# Unit digit of a^(b^c), for small positive a, b, c
e = b ** c
k = (e - 1) % 4 + 1 # position 1 to 4 in the cycle
return pow(a, k, 10)
print(tower_unit_digit(3, 4, 5)) # 1The formula (e - 1) % 4 + 1 maps a remainder of 0 to position 4, not to position 0. Position 0 would give a^0 = 1, which is wrong for 3^(4^5).
Last two digits of sums and products
Work mod 100 and ignore everything else. For example, 37 × 43 gives 1591, so the last two digits are 91. Mod 100 arithmetic lets you multiply the remainders first: 37 × 43 mod 100 = 91.
Last two digits of powers: cycles and the 10k+1 pattern
The last two digits of powers of 7 repeat with period 4, because 7^4 = 2401 ends in 01. So 7^2026 ends in the same two digits as 7^2, since 2026 mod 4 = 2. The answer is 49.
Numbers of the form 10k+1 follow a simpler rule. Since (1 + 20)^n = 1 + 20n + (terms divisible by 400), we get 21^n ≡ 1 + 20n (mod 100). For n = 5, this gives 101, so the last two digits are 01.
Splitting mod 100 into mod 4 and mod 25
Because 4 and 25 share no factors, a remainder mod 100 is fixed by its remainders mod 4 and mod 25. For 7^2026:
- Mod 4: 7 ≡ −1, so 7^2026 ≡ 1.
- Mod 25: 7^2 = 49 ≡ −1, so 7^6 ≡ −1 ≡ 24. Since 2026 ≡ 6 (mod 20), the result is 24.
The number that is 1 mod 4 and 24 mod 25 is 49, which matches the cycle result.
Why trailing zeros depend on the factors 2 and 5
Each trailing zero requires a factor of 10, which is 2 × 5. A number with 2^a and 5^b as factors ends in min(a, b) zeros. For 1200 = 2^4 × 3 × 5^2, the answer is min(4, 2) = 2.
For n!, factors of 2 always outnumber factors of 5, so only the factors of 5 count. The zero count is floor(n/5) + floor(n/25) + floor(n/125) + ...
def trailing_zeros_factorial(n):
count = 0
p = 5
while p <= n:
count += n // p
p *= 5
return count
print(trailing_zeros_factorial(100)) # 24Exercise
What are the unit digit of 2^(3^2) and the last two digits of 21^7?
Show answer
2^(3^2) = 2^9. The cycle of 2 is 2, 4, 8, 6, and position 9 maps to (9 − 1) mod 4 + 1 = 1, so the unit digit is 2. For 21^7, use 21^n ≡ 1 + 20n (mod 100): 1 + 140 = 141, so the last two digits are 41.