Sub topic 4
Negative remainders as a shortcut
This chapter assumes you can compute a remainder by long division and read the notation a ≡ b (mod n). It also assumes you know that remainders of sums and products can be taken factor by factor. Those ideas come from the earlier chapters. Here they are applied to one habit: choosing the remainder with the smallest size, even when it is negative.
The idea
The remainder of 19 on division by 20 is 19. It is also true that 19 is 1 less than a multiple of 20, so
19 ≡ -1 (mod 20)
Both statements are correct. Congruence only asks that the difference between the two numbers be a multiple of the modulus. Here 19 - (-1) = 20, which is a multiple of 20. So -1 is another valid label for the same remainder class.
Any number a can be written with two labels:
- the usual remainder r, with 0 ≤ r < n
- the negative label r - n, which lies between -n and 0
If r is more than half of n, the negative label is smaller in size and is easier to work with. For example, 18 ≡ -2 (mod 20). Squaring 18 is harder than squaring -2, and the negative form often gives a pattern.
The final answer to a CAT question is almost always a non-negative remainder. When your working ends in a negative number, add n until the result lies between 0 and n - 1.
Why it helps
Two facts make negative labels powerful:
- (-1) raised to an even power is 1, and raised to an odd power is -1.
- A product of small numbers is easier to handle than a product of numbers close to n.
Here is a worked example. Find the remainder when 98 × 99 × 101 is divided by 100.
- Rewrite each factor: 98 ≡ -2, 99 ≡ -1, 101 ≡ 1.
- Multiply: (-2)(-1)(1) = 2.
- The remainder is 2.
Computing 98 × 99 × 101 = 979902 and dividing confirms it, but the shortcut took three small steps.
Powers of a number just below the modulus
The most common CAT pattern is a base that is one less than the modulus. Then the base is ≡ -1, and the whole power collapses.
Find the remainder when 6^83 is divided by 7.
- 6 ≡ -1 (mod 7).
- 6^83 ≡ (-1)^83 = -1.
- Add 7: -1 + 7 = 6.
The remainder is 6.
Now a case where the exponent is even. Find the remainder when 7^100 is divided by 8.
- 7 ≡ -1 (mod 8).
- 7^100 ≡ (-1)^100 = 1.
The remainder is 1.
Without the negative label, you would have to look for the cycle of powers of 7 modulo 8. The cycle is 7, 1, 7, 1, and it is short, but the negative label gives the answer at once and works for any modulus.
When the base is not exactly -1
Sometimes the base is -1 only after one step of squaring or raising to a small power. You then look for a power that gives -1, and from that power you get a cycle.
Find the remainder when 5^50 is divided by 13.
- 5^2 = 25 = 26 - 1, so 5^2 ≡ -1 (mod 13).
- 5^50 = (5^2)^25 ≡ (-1)^25 = -1.
- Add 13: the remainder is 12.
Find the remainder when 2^100 is divided by 33.
- 2^5 = 32 ≡ -1 (mod 33).
- 2^10 = (2^5)^2 ≡ (-1)^2 = 1.
- 2^100 = (2^10)^10 ≡ 1.
The remainder is 1. Notice that once a power equals -1, the next power in the cycle equals 1, so the cycle length is exactly twice the exponent that gave -1.
Sometimes the negative label is not -1 but a small number such as -3. Find the remainder when 17^45 is divided by 20.
- 17 ≡ -3 (mod 20).
- (-3)^2 = 9 and 9^2 = 81 ≡ 1, so (-3)^4 ≡ 1.
- 45 = 4 × 11 + 1, so 17^45 ≡ (-3)^1 = -3.
- Add 20: the remainder is 17.
Useful negative labels
| Modulus n | Number | Negative label |
|---|---|---|
| 5 | 4 | -1 |
| 7 | 5 | -2 |
| 9 | 8 | -1 |
| 10 | 9 | -1 |
| 11 | 10 | -1 |
| 12 | 11 | -1 |
| 13 | 8 | -5 |
| 17 | 16 | -1 |
The rule for finding the label is simple: subtract n from the number. For a number a larger than n, first reduce it modulo n, then subtract n if the remainder is more than about half of n.
Checking the shortcut with code
Python's % operator always returns a non-negative result for a positive modulus, so it gives the final answer directly. The code below checks each worked example, and it also checks that a negative label gives the same class as the positive one.
print(pow(6, 83, 7)) # 6
print(pow(7, 100, 8)) # 1
print(pow(5, 50, 13)) # 12
print(pow(2, 100, 33)) # 1
print(pow(17, 45, 20)) # 17
# a negative label and its positive partner are the same class
print((-1) % 20, 19 % 20) # 19 19
print(((-2) * (-1) * 1) % 100) # 2
print((98 * 99 * 101) % 100) # 2
print((-1) ** 83 % 7) # 6The last line shows the behaviour that matters in practice: (-1) ** 83 is -1, and -1 % 7 is 6, which matches the "add n" step you do by hand.
Choosing a label: a decision flow
Common errors
- Reporting a negative remainder. A remainder on division is between 0 and n - 1. If your working ends at -1 modulo 7, the answer is 6, not -1.
- Getting the sign wrong with the exponent. (-1)^n is -1 only when n is odd. Check the parity of the exponent before writing the result.
- Mixing moduli. The label 18 ≡ -2 holds modulo 20 but not modulo 19. Always state the modulus when you switch labels.
- Applying a negative label to division. Remainders can be added, subtracted and multiplied factor by factor. They cannot be divided in the same way, because 12 ≡ 2 (mod 10) does not mean 12/2 ≡ 2/2 (mod 10). Avoid dividing congruences unless the divisor shares no factor with the modulus.
- Forgetting the sign of a product. In (-2)(-3)(-1), three negative factors give a negative product, -6. Count the number of negative signs.
A sum of terms
Negative labels also simplify sums. Find the remainder when 12^100 + 14^100 is divided by 13.
- 12 ≡ -1 (mod 13) and 14 ≡ 1 (mod 13).
- 12^100 ≡ (-1)^100 = 1.
- 14^100 ≡ 1^100 = 1.
- The sum is 1 + 1 = 2.
The remainder is 2. Each term was handled alone, then the remainders were added, as the earlier chapter on sums and products allows.
Summary of the method
- Reduce each factor or base modulo n.
- If a remainder is more than half of n, replace it with its negative label.
- For powers, look for a power that equals -1 or 1, then reduce the exponent.
- Combine the small values.
- If the result is negative, add n.
Exercise
Find the remainder when 24^37 is divided by 25.
Show answer
24 ≡ -1 (mod 25). So 24^37 ≡ (-1)^37 = -1. Adding 25 gives 24. The remainder is 24.
Exercise
Find the remainder when 12^100 + 14^100 + 5^50 is divided by 13, using the results worked in this chapter.
Show answer
From the chapter, 12^100 + 14^100 ≡ 1 + 1 = 2 (mod 13), and 5^50 ≡ -1 ≡ 12 (mod 13). The total is 2 + 12 = 14, and 14 - 13 = 1. The remainder is 1.
Exercise
Find the remainder when 2^90 is divided by 17.
Show answer
2^4 = 16 ≡ -1 (mod 17), so 2^8 ≡ 1. Since 90 = 8 × 11 + 2, 2^90 ≡ 2^2 = 4. The remainder is 4.