Sub topic 13
Mixed CAT Problems: Picking a Method and Checking the Answer
This chapter assumes you know the earlier ideas in this tutorial. These are remainders mod 10 and mod 100, the cycles of unit digits, the power-tower rule, the (10k+1) pattern, the mod 4 and mod 25 split, and the factor-counting rule for trailing zeros. Here you will practise choosing between them. You will also learn quick checks that catch most mistakes in under two minutes.
Step 1: Name the question
Almost every problem in this family asks for one of three things:
- Unit digit: the remainder mod 10.
- Last two digits: the remainder mod 100.
- Trailing zeros: the number of complete factors of 10, which is the smaller of the exponent of 2 and the exponent of 5.
Decide which of the three you are answering before doing any arithmetic. Then look at the shape of the expression: a sum, a product, a large power, a tower, or a factorial.
| Shape of the problem | Method | First thing to check |
|---|---|---|
| Sum or product of many terms, unit digit | Reduce each term mod 10, then combine | Does a factor ending in 0 or an even-times-5 pair collapse the product? |
| a^n, unit digit | Cycle of a's last digit, position (n − 1) mod cycle length | Is the remainder 0? Then use the last position |
| a^(b^c), unit digit | Find b^c mod the cycle length, then use the cycle | Is b a multiple of the cycle length (for example 4)? |
| Sum of factorials, last digits | Drop terms that end in enough zeros | From which k does k! end in 00? (From 10!) |
| a^n, last two digits, a ends in 1 | (1 + 10k)^n ≡ 1 + 10kn (mod 100) | Is a ≡ 1 (mod 10)? |
| a^n, last two digits, other a | Find a short cycle mod 100, or split into mod 4 and mod 25 | Is a odd and not a multiple of 5? Then a cycle exists |
| Zeros of a product or power | Write the prime factorisation, take min(2s, 5s) | Count both primes. Do not assume 5 is the scarce one |
| Zeros of n! | Add floor(n/5) + floor(n/25) + floor(n/125) + … | Include every power of 5 up to n |
| Zeros of n! in base b | Factorise b, divide each prime's exponent in n! by its exponent in b, take the minimum | Take floor of each ratio before the minimum |
Step 2: Work three mixed examples
Example A: a sum of factorials
Find the last two digits of 1! + 2! + … + 100!.
From 10! onward, each factorial contains the factors 2 × 5 twice over (5 and 10), so it ends in at least two zeros. Only 1! through 9! matter. Reduce each mod 100:
- 1, 2, 6, 24
- 5! = 120 gives 20
- 6! = 720 gives 20
- 7! = 5040 gives 40
- 8! = 40320 gives 20
- 9! = 362880 gives 80
The sum is 1 + 2 + 6 + 24 + 20 + 20 + 40 + 20 + 80 = 213, so the last two digits are 13.
The unit digit of the same sum is 3. This agrees with the quicker argument that 5! onward end in 0, so only 1 + 2 + 6 + 24 = 33 matters.
Example B: a large power with base ending in 1
Find the last two digits of 21^37.
Write 21 = 1 + 20. Then (1 + 20)^37 ≡ 1 + 20 × 37 = 741 ≡ 41 (mod 100). Higher terms of the expansion carry a factor 20² = 400, so they vanish mod 100.
Example C: a power of 2 with a large exponent
Find the last two digits of 2^100.
The base is even, so there is no simple cycle from the start. Split the modulus.
- Mod 4: 2^100 is divisible by 4, so the remainder is 0.
- Mod 25: φ(25) = 20, and 2 shares no factor with 25, so 2^20 ≡ 1. Hence 2^100 = (2^20)^5 ≡ 1.
Find the number below 100 that is 0 mod 4 and 1 mod 25. The numbers 1, 26, 51, 76 are 1 mod 25, and only 76 is divisible by 4. The answer is 76.
Step 3: Zeros in products and non-decimal bases
For a product, write each factor in primes first. Take 12^10 × 15^8 × 20^6:
- 12^10 = 2^20 × 3^10
- 15^8 = 3^8 × 5^8
- 20^6 = 2^12 × 5^6
Total exponent of 2 is 32, and of 5 is 14. The number of trailing zeros is min(32, 14) = 14.
For a factorial in another base, factorise the base. To count trailing zeros of 50! in base 12, note 12 = 2² × 3.
- Exponent of 2 in 50! is 25 + 12 + 6 + 3 + 1 = 47. Divided by 2 (the exponent in 12), this gives floor(47/2) = 23.
- Exponent of 3 in 50! is 16 + 5 + 1 = 22. Divided by 1, this gives 22.
The answer is min(23, 22) = 22. In this base, 3 is the scarce prime, not the larger one.
Step 4: Check the answer in under two minutes
A fast check does not have to repeat the whole solution. Use one of these.
- Range and parity check. A unit digit lies between 0 and 9. A power of an odd number is odd, so its last two digits form an odd number. A power of a number ending in 5 ends in 5. A power of an even number is even.
- Smaller exponent check. Test your cycle claim on a small case. For 7^n, compute 7^1, 7^2, 7^3, 7^4 and confirm the cycle 7, 9, 3, 1 before applying it.
- Size check for factorials. The number of zeros of n! is about n/4 (a little less). For 125!, that is about 31, and the exact formula gives 25 + 5 + 1 = 31. If you get 40 or 15, something went wrong.
- Exact formula check. The exponent of 5 in n! equals (n − s) / 4, where s is the digit sum of n written in base 5. For 100, which is 400 in base 5, this gives (100 − 4) / 4 = 24, which matches 20 + 4.
- Two-route check. Solve a last-two-digits question by the cycle method and by the mod 4 and mod 25 split. If both give 76, you are done.
A frequent mistake is the remainder-0 case. If the exponent is a multiple of the cycle length, use the last entry of the cycle, not the first. For 3^(4^5), 4^5 = 1024 is a multiple of 4, so you read the 4th entry of 3, 9, 7, 1, which is 1.
Step 5: Verify with code while you practise
Python's built-in pow with three arguments, plus math.factorial, lets you confirm any hand answer. Use it when you practise, not in the exam.
from math import factorial
# Example A: last two digits of 1! + ... + 100!
print(sum(factorial(k) for k in range(1, 101)) % 100) # 13
# Example B: last two digits of 21^37
print(pow(21, 37, 100)) # 41
# Example C: last two digits of 2^100
print(pow(2, 100, 100)) # 76
# Tower: unit digit of 3^(4^5)
print(pow(3, 4**5, 10)) # 1
def zeros_in_base(n, base):
"""Trailing zeros of n! written in the given base."""
f = factorial(n)
count = 0
while f % base == 0:
f //= base
count += 1
return count
print(zeros_in_base(125, 10)) # 31
print(zeros_in_base(50, 12)) # 22The brute-force function zeros_in_base divides out the base repeatedly. It is slow for large n, but fine for checking small cases against the formulas.
Common traps
- Wrong modulus. Do not reduce an exponent mod 10 or mod 100. The exponent is reduced mod the cycle length, which is 1, 2 or 4 for unit digits.
- Zero exponent. Any non-zero number to the power 0 is 1. A cycle position of 0 only arises from your own remainder, never from the exponent itself.
- Counting only 5s in a product. In 2^3 × 5^7, the 2s are scarce. The answer is 3, not 7.
- Forgetting 25 and 125 in factorials. 25! has 5 + 1 = 6 zeros, not 5.
- Using the cycle method on even bases mod 100. Cycles for powers of 2 mod 100 start only after a few terms, so the split into mod 4 and mod 25 is safer.
Exercise
Find the last two digits of 1! + 2! + 3! + … + 10!, and then find the unit digit of 17^(2^10).
Show answer
From 10! onward every term ends in 00, so use 1! through 9!, which sum to 213 mod 100 = 13. The last two digits are 13. For the second part, 17 ends in 7, with cycle 7, 9, 3, 1. The exponent 2^10 = 1024 is a multiple of 4, so use the 4th position, which is 1. The unit digit is 1.
Exercise
How many trailing zeros does 200! have, and how many does 18^20 × 35^12 have?
Show answer
For 200!, the count is 40 + 8 + 1 = 49. For the product, 18^20 = 2^20 × 3^40 and 35^12 = 5^12 × 7^12. The exponent of 2 is 20 and the exponent of 5 is 12, so the number has min(20, 12) = 12 trailing zeros.
Exercise
Find the last two digits of 3^100 using the mod 4 and mod 25 split, then check with the exponent cycle of 3 mod 100.
Show answer
Mod 4, 3^100 = (3^2)^50 ≡ 1. Mod 25, φ(25) = 20, so 3^100 = (3^20)^5 ≡ 1. A number that is 1 mod 4 and 1 mod 25 is 1 mod 100, so the answer is 01. Check: 3^20 ≡ 1 mod 100, so 3^100 ≡ 1, which agrees.