THE PROBLEM
Let be a function that reverses the digits of . For example, and . Find the number of positive integers such that is divisible by .
Difficulty: Olympiad Prequalifier · ★★☆☆☆
Source: Olympiad Prequalifier Practice Set
Topics: Number Theory · Digit Manipulation · Modular Arithmetic
Answer:
THE KEY IDEA
You never need to actually reverse the number. The last digit of is simply the first digit of . Since divisibility by depends only on the units digit, only the first and last digits of matter — everything in between is irrelevant.
THE SOLUTION
Let the first digit of be and its last digit be .
When we reverse the digits, the digit moves to the units place. So the units digit of is , while the units digit of is . Therefore,
For to be divisible by , we need
Since , , and both are digits,
The only multiple of in this range is , so
Now count by number of digits.
Case 1: One-digit numbers
For , we have . Thus,
This equals only when .
So there is 1 such number.
Case 2: Two-digit numbers
For , we need
where
For every choice of , there is exactly one valid choice
Thus there are 9 such numbers.
Case 3:
Here and , so
Thus there are 0 such numbers.
Adding the cases,
Therefore,
WHY THE OBVIOUS APPROACH IS SLOW
The natural instinct is to compute for every , add it to , and check divisibility by . That is 100 reversals and 100 additions — slow, error-prone, and completely unnecessary.
The problem only asks about divisibility by , so only the units digit of the sum matters. And the units digit of is controlled entirely by the first digit of . The middle digits never enter the calculation.
THE INSIGHT
When a problem involves divisibility by , immediately isolate the units digit. If a complicated operation such as digit reversal appears, ask:
Which digits of the original number actually affect that units digit?
Usually, most of the number is irrelevant. This same instinct applies to any “last digit” or “mod ” problem — reduce the problem to the digits that matter before computing anything.
GENERALIZATION
What if we replaced with ?
Then we would need
and the count would change because can now equal or . The structure of the argument is identical — only the arithmetic of the digit sum changes.
This works because
so digit sums control divisibility by . For a general modulus , the units digit alone is usually not enough; the useful digits depend on the modulus.
CHALLENGE
Find the number of positive integers $m < 10^4$ such that $m + f(m)$ is divisible by 9.