Sub topic 9
Digits as algebra: reversals and digit relations
This chapter turns a number's digits into algebraic variables. That lets you solve reversal, swap and digit-relation questions with one or two equations instead of trial and error. It assumes you can write a number as a sum of digits times powers of 10, solve linear equations, and check divisibility by 9 and 11.
From digits to an expression
A two-digit number with tens digit a and units digit b is not the product ab. It is the sum 10a + b. The same place-value idea gives every other form you will need.
| Description | Algebraic form | Digit limits |
|---|---|---|
| Two-digit number | 10a + b | a from 1 to 9, b from 0 to 9 |
| Its reversal | 10b + a | a number only if b ≥ 1 when you need two digits |
| Three-digit number | 100a + 10b + c | a from 1 to 9, b and c from 0 to 9 |
| Its reversal | 100c + 10b + a | c ≥ 1 if it must stay three-digit |
| Digit d written to the right of N | 10N + d | d from 0 to 9 |
| Digit d written to the left of a k-digit N | d · 10^k + N | d from 1 to 9 |
The digit limits are part of the problem. Many questions have an algebraic family of solutions, and the limits cut it down to one answer.
Two-digit reversals
Take N = 10a + b and its reversal R = 10b + a. Two combinations are worth memorising.
- Sum:
N + R = 11(a + b). The sum is always a multiple of 11. - Difference:
R − N = 9(b − a). The difference is always a multiple of 9.
If a question says the difference between a number and its reversal is 27, you know at once that the digits differ by 3. You do not need to try any numbers.
print(all(((10 * a + b) - (10 * b + a)) % 9 == 0
for a in range(1, 10) for b in range(10))) # TrueWorked example 1: a sum and a difference
The digits of a two-digit number add up to 11. The number formed by reversing the digits is 27 more than the original. Find the number.
- Let the number be
10a + b. The first condition givesa + b = 11. - The second condition gives
(10b + a) − (10a + b) = 27, which simplifies to9(b − a) = 27, sob − a = 3. - Adding the two equations gives
2b = 14, sob = 7anda = 4.
The number is 47. Check: the reversal is 74, and 74 − 47 = 27. ✓
A brute-force search over all two-digit numbers confirms that 47 is the only solution:
solutions = [n for n in range(10, 100)
if (n % 10) * 10 + n // 10 - n == 27 and n // 10 + n % 10 == 11]
print(solutions) # [47]Worked example 2: a number as a multiple of its digit sum
A two-digit number is 4 times the sum of its digits. Reversing the digits gives a number 18 more than the original. Find it.
- From the first condition,
10a + b = 4(a + b), so6a = 3bandb = 2a. - From the second,
9(b − a) = 18, sob − a = 2. - Substituting
b = 2agivesa = 2andb = 4.
The number is 24. Check: 4 × (2 + 4) = 24, and 42 − 24 = 18. ✓
Notice that the first condition alone leaves four candidates: 12, 24, 36 and 48. The second condition picks one.
Three-digit reversals
For N = 100a + 10b + c and R = 100c + 10b + a, the middle digit cancels in the difference:
N − R = 99(a − c)N + R = 101(a + c) + 20b
The difference does not depend on b. This has two consequences you can use.
- A difference such as 297 gives
a − c = 3directly. - Each valid pair
(a, c)works with every middle digit from 0 to 9. A question that asks "how many numbers" is therefore a counting question over(a, c)pairs, multiplied by 10.
print(all(((100 * a + 10 * b + c) - (100 * c + 10 * b + a)) % 99 == 0
for a in range(1, 10) for b in range(10) for c in range(10))) # TrueThe sum is less tidy. The factor 101 on a + c and 20 on b mean that sums of three-digit reversals rarely give clean divisibility facts. For three-digit numbers, lean on the difference.
Adding or removing a digit
When a digit is attached to a number, use the place-value forms from the table.
Worked example 3: appending a digit
Writing the digit 1 to the right of a two-digit number increases the number by 154. Find the number.
- The new number is
10N + 1. The increase is(10N + 1) − N = 9N + 1. - Setting
9N + 1 = 154gives9N = 153, soN = 17.
Check: 171 − 17 = 154. ✓
The same idea works in reverse. If a digit d is deleted from the right end of M, then M = 10N + d, where N is the number that remains. Deleting a digit from the left of a k-digit number removes d · 10^k.
Digit relations as constraints
Many questions describe digits in words rather than through reversals. Translate each phrase into an equation or an inequality.
- "The tens digit is twice the units digit" becomes
a = 2b. - "The digits are consecutive" becomes
|a − b| = 1. - "The digits are in arithmetic progression" becomes
2b = a + c. - "The product of the digits is 24" becomes
ab = 24, and the factor pairs with both factors at most 9 are (3, 8), (4, 6), (6, 4) and (8, 3). - "The number is divisible by 9" becomes
a + b + c ≡ 0 (mod 9).
You usually end up with fewer equations than unknowns. A three-digit number has three digits, but a problem might give only two equations. The limit "each digit is an integer from 0 to 9" is the third piece of information. List the few possibilities that fit, then test them against the remaining condition.
def three_digit_relations():
found = []
for n in range(100, 1000):
a, b, c = n // 100, n // 10 % 10, n % 10
if 2 * b == a + c and a + b + c == 12:
found.append(n)
return found
print(three_digit_relations()) # [147, 246, 345, 444, 543, 642, 741]Here 2b = a + c and a + b + c = 12 combine to 3b = 12, so b = 4 and a + c = 8. That gives the seven numbers above without any search, because a runs from 1 to 8 with c = 8 − a.
Choosing a method
The diagram shows how to decide between the approaches in this chapter.
Common errors
- Writing the number as
a × borabcinstead of10a + bor100a + 10b + c. - Forgetting that the leading digit cannot be 0. For a reversal question, also ask whether the units digit may be 0.
- Subtracting in the wrong order.
N − Ris9(a − b)andR − Nis9(b − a). Decide which number is larger from the wording. - Dropping a solution after finding
a − c = k. Each middle digit gives another valid number. - Not checking the answer against every statement. One condition can be satisfied by an answer that breaks another.
Quick checks
- Casting out nines: a number and its reversal leave the same remainder modulo 9, so their difference is divisible by 9. If a worked answer breaks this, an error has crept in.
- The sum of a two-digit number and its reversal is divisible by 11. The same holds for any four-digit palindromic structure, but a general three-digit sum is not.
- Substitute the final digits into every condition in the question, not only the last one you used.
Exercise
The difference between a two-digit number and the number obtained by reversing its digits is 45. The sum of its digits is 9. Find the number.
Show answer
Let the number be 10a + b with a larger than b. The difference is 9(a − b) = 45, so a − b = 5. With a + b = 9, adding gives 2a = 14, so a = 7 and b = 2. The number is 72. Check: 72 − 27 = 45. ✓
Exercise
How many three-digit numbers N have the property that N minus its reversal equals 198, where the reversal is also a three-digit number?
Show answer
The difference is 99(a − c) = 198, so a − c = 2. The reversal must be three-digit, so c ≥ 1. With a = c + 2 ≤ 9, c runs from 1 to 7, which gives 7 pairs (a, c). The middle digit b is free, with 10 choices. The total is 7 × 10 = 70.