Additional Topics for the TMUA

Modulo arithmetic: remainders, equivalence and useful methods

What you will get from this section. You will learn what abmodma\equiv b\mod m means and the basic rules of modulo arithmetic. You will then see how these rules can be used to solve problems that might otherwise be difficult, including some that could occur in the TMUA. Although modulo arithmetic is not required knowledge for the TMUA, and any question for which it is useful can also be solved using ordinary arguments about remainders and divisibility, it can turn lengthy calculations and proofs into very short ones. It is therefore an extremely useful and interesting additional technique to learn.

TMUA Relevance Score: 6/10

Basic definition

Let mm be a positive integer. We write

to mean that aa and bb have the same remainder upon division by mm. We read this as “aa is equivalent to bb modulo mm”.

For example, consider the numbers 2424, 1010, 33 and 4-4. We have

  • 24=3×7+324=3\times7+3;
  • 10=1×7+310=1\times7+3;
  • 3=0×7+33=0\times7+3;
  • 4=(1)×7+3-4=(-1)\times7+3.

They all leave remainder 33 when divided by 77, so

241034mod724\equiv10\equiv3\equiv-4\mod7.

It is also often useful to characterise equivalence modulo mm in the following way:

This is equivalent to the first definition and is sometimes the more useful characterisation.

Adding and subtracting multiples of mm

We may add or subtract any multiple of mm from either side without changing the equivalence modulo mm.

Why is this true? If aa and bb have the same remainder modulo mm, then so do a+pma+pm and b+qmb+qm, since adding or subtracting a multiple of mm does not change the remainder upon division by mm.

For example, 221mod722\equiv1\mod7. Adding 1414, which is a multiple of 77, to 22=3×7+122=3\times7+1 gives

22+14=3×7+1+2×7=5×7+122+14=3\times7+1+2\times7=5\times7+1,

so the remainder is still 11.

As another example, 2250mod722\equiv50\mod7 means that 2222 and 5050 have the same remainder modulo 77. If we add 1414 to 2222 while subtracting 2828 from 5050, neither remainder changes, so the resulting numbers remain equivalent modulo 77. We do not even need to know what the common remainder is—although, in this case, it is 11.

The most important takeaway intuition

Equivalent is the most appropriate way to understand the relationship between such aa and bb. This is not equality in the ordinary sense, but they do have equal remainders upon division by mm.

Another way to envisage this is to put all integers into groups according to their remainder upon division by mm. Then aa and bb belong to the same group. This is what mathematicians call an equivalence relation, which satisfies three key properties:

  • every integer is equivalent to itself;
  • if abmodma\equiv b\mod m, then bamodmb\equiv a\mod m;
  • if abmodma\equiv b\mod m and bcmodmb\equiv c\mod m, then acmodma\equiv c\mod m.

This leads to the important basic operations that we can perform in modulo arithmetic. Although aa and bb are not equal in the ordinary sense, they are regarded as the same modulo mm. Consequently, some of the operations we can perform on ordinary equations can also be performed on equivalences modulo mm. This is the next intuition to build.

Basic properties

As mentioned above, we may treat abmodma\equiv b\mod m almost like an equation when adding, subtracting and multiplying. There is, however, an important difference when we try to reverse these operations.

Adding kk to both sides

For any integer kk,

The forward implication follows by adding kk to both sides. The converse follows by adding k-k to both sides.

Multiplying both sides by kk

For every integer kk,

This is less obvious, but it is always true. If mm divides aba-b, then it must also divide k(ab)=akbkk(a-b)=ak-bk. Notice that the implication arrow only goes from left to right, unlike the equivalence for addition. The converse is not always true. For example, 28mod62\equiv8\mod6, but dividing both sides by 22 would give 14mod61\equiv4\mod6, which is false.

Cancelling kk from both sides

The converse of multiplying both sides by kk would allow us to cancel a non-zero integer kk from both sides. As shown above, this is not valid in general. The exact condition is:

First, we prove the if direction.

Suppose that gcd(k,m)=1\gcd(k,m)=1 and akbkmodmak\equiv bk\mod m. Then mm divides k(ab)k(a-b). Since kk and mm have no prime factors in common, all the prime factors of mm, with their required multiplicities, must divide aba-b. Hence mm divides aba-b, so abmodma\equiv b\mod m.

We now prove the only if direction by contradiction.

Suppose, for contradiction, that cancellation is valid for all integers aa and bb, but d=gcd(k,m)>1d=\gcd(k,m)>1. Take a=0a=0 and b=m/db=m/d. Since dd divides kk, the number bk=(m/d)k=m(k/d)bk=(m/d)k=m(k/d) is divisible by mm. Therefore, akbkmodmak\equiv bk\mod m.

However, since d>1d>1, we have 0<b<m0<b<m, so bb is not divisible by mm. Hence a≢bmodma\not\equiv b\mod m. This contradicts our assumption that cancellation is valid for all integers aa and bb. Therefore, cancellation can be valid for all integers aa and bb only if gcd(k,m)=1\gcd(k,m)=1.

Combining two equivalences

We can do more than add the same integer to, or multiply both sides of, a single equivalence modulo mm. We can also add, subtract and multiply two equivalences.

If abmodma\equiv b\mod m and cdmodmc\equiv d\mod m, then

Proof of the multiplication property

All the properties above can be proved directly from the basic definition. We will prove the least obvious one: if abmodma\equiv b\mod m and cdmodmc\equiv d\mod m, then acbdmodmac\equiv bd\mod m.

Since abmodma\equiv b\mod m, the difference aba-b is divisible by mm. Similarly, cdc-d is divisible by mm. Now

acbd=c(ab)+b(cd).ac-bd=c(a-b)+b(c-d).

Both terms on the right are divisible by mm, so their sum is divisible by mm. Therefore, mm divides acbdac-bd, which proves that acbdmodmac\equiv bd\mod m.

Raising both sides to a positive integer power

The multiplication property immediately gives a further useful rule. We may multiply abmodma\equiv b\mod m by itself repeatedly to obtain

This is perhaps the biggest cheat rule. For example, knowing that 71mod47\equiv-1\mod4 immediately tells us that 7k1mod47^k\equiv1\mod4 for every positive even integer kk. You will see many problems shamelessly exploit this shortcut. 😊

Useful methods through TMUA-style examples

Modulo arithmetic develops into a deep topic studied further in university mathematics. For our purposes, however, we need no more than the basic results outlined above. The contrasting examples that follow demonstrate different techniques for using these results to shorten solutions and make the underlying logic easier to follow.

Example 1: Replacing a number inside an algebraic expression

An integer nn leaves remainder 55 when divided by 77. What remainder does n4+3n2+2nn^4+3n^2+2n leave when divided by 77?

We are given that n5mod7n\equiv5\mod7. Since 52mod75\equiv-2\mod7, we may use the more convenient representative 2-2 instead. Applying the addition, multiplication and positive-power rules gives

n4+3n2+2n(2)4+3(2)2+2(2)=16+124=243mod7n^4+3n^2+2n\equiv(-2)^4+3(-2)^2+2(-2)=16+12-4=24\equiv3\mod7.

The required remainder is 33.

Without modulo arithmetic, we could write n=7q+5n=7q+5, substitute this into the expression and expand. Modulo arithmetic avoids introducing qq and discards all multiples of 77 immediately.

Example 2: Powers and repeating cycles

What is the remainder when 32026+720263^{2026}+7^{2026} is divided by 1010?

The powers of 33 modulo 1010 repeat as

3,9,7,1,3,9,7,1,3,9,7,1,3,9,7,1,\ldots

Indeed, 313mod103^1\equiv3\mod10, 329mod103^2\equiv9\mod10, 33277mod103^3\equiv27\equiv7\mod10 and 34=33337=211mod103^4=3\cdot3^3\equiv3\cdot7=21\equiv1\mod10. Multiplying by 33 once more returns us to 33, so the cycle repeats.

Similarly, you can verify that the powers of 77 repeat as

7,9,3,1,7,9,3,1,7,9,3,1,7,9,3,1,\ldots

Both cycles have length 44, and 2026=4×506+22026=4\times506+2. The exponent therefore occupies the second position in each cycle, so

320269mod103^{2026}\equiv9\mod10 and 720269mod107^{2026}\equiv9\mod10.

Hence

32026+720269+9=188mod103^{2026}+7^{2026}\equiv9+9=18\equiv8\mod10,

so the required remainder is 88.

This particular example is not significantly simplified by modulo arithmetic, but it illustrates how modulo notation can make calculations and logical arguments more systematic and concise.

Example 3: Proving that an integer equation is impossible

Can integers xx, yy and zz satisfy

x2+y2=4z+3x^2+y^2=4z+3?

Every integer is equivalent modulo 44 to one of 00, 11, 22 or 33. Squaring these four representatives gives remainders 00, 11, 00 and 11, respectively. Therefore, every square is equivalent to either 00 or 11 modulo 44.

It follows that x2+y2x^2+y^2 can only be equivalent to 00, 11 or 22 modulo 44. However, 4z+33mod44z+3\equiv3\mod4. The two sides can never be equivalent modulo 44, so they cannot be equal. Therefore, the equation has no integer solutions.

A case-by-case argument based on whether xx and yy are even or odd would reach the same conclusion, but modulo arithmetic expresses all four cases together.

Example 4: Following a recurrence relation modulo mm

The sequence (un)(u_n) is defined by u1=1u_1=1 and un+1=2un+1u_{n+1}=2u_n+1.

For which positive integers nn is unu_n divisible by 55?

We need only follow the remainders modulo 55:

13201.1\longmapsto3\longmapsto2\longmapsto0\longmapsto1.

The remainder 11 has returned. Since each new remainder is determined entirely by the previous one, the same cycle must now repeat:

1,3,2,0,1,3,2,0,1,3,2,0,1,3,2,0,\ldots

The remainder is 00 every fourth term. Therefore, unu_n is divisible by 55 precisely when nn is divisible by 44.

We could instead derive un=2n1u_n=2^n-1 and study the remainders of the powers of 22. Following the recurrence directly is quicker.

Example 5: The units digit of a power tower

Find the units digit of

777777.7^{7^{7^{7^{7^{7}}}}}.

The units digit of an integer is determined by its remainder modulo 1010. The powers of 77 modulo 1010 repeat in a cycle of length 44:

7,9,3,1,7,9,3,1,7,9,3,1,7,9,3,1,\ldots

We therefore need to determine the remainder when the exponent 777777^{7^{7^{7^{7}}}} is divided by 44.

Since 73mod47\equiv3\mod4 and the exponent 77777^{7^{7^{7}}} is odd,

777773odd(1)odd13mod4.7^{7^{7^{7^{7}}}}\equiv3^{\text{odd}}\equiv(-1)^{\text{odd}}\equiv-1\equiv3\mod4.

Here, I replaced 33 with 1-1 because 31mod43\equiv-1\mod4. Nice, right? 😊

The exponent therefore occupies the third position in the cycle of powers of 77 modulo 1010. Hence

7777773mod10,7^{7^{7^{7^{7^{7}}}}}\equiv3\mod10,

so the units digit is 33.

Summary

The statement abmodma\equiv b\mod m means that aa and bb leave the same remainder when divided by mm. Working modulo mm, we can: