MATH2400 1,932 words·10 min read

Modular Arithmetic

The Mod Operator#

Recall the Division Theorem; for any integers aa and bb with b≠0b \neq 0, there exist unique integers qq and rr such that

a=qb+r,0≤r<∣b∣.a = qb + r, \quad 0 \leq r < |b|.

In a lot of situations we don't actually care about the quotient qq at all; the remainder rr is the interesting part, so we give it its own operator.

Note

Definition
The modulo operator mod\text{mod} returns the canonical remainder when one integer is divided by another. Given integers aa and bb with b≠0b \neq 0, we write a mod ba \bmod b, read as "aa modulo bb", to mean the smallest non-negative remainder when aa is divided by bb. That is,

a mod b=r, where a=qb+r and 0≤r<∣b∣ for some q,r∈Z.a \bmod b = r, \text{ where } a = qb + r \text{ and } 0 \leq r < |b| \text{ for some } q,r \in \mathbb{Z}.

Basically, a mod ba \bmod b is just "the remainder when you divide aa by bb"; we throw away the quotient and keep only the leftover part. Notice that a mod b=0a \bmod b = 0 if and only if b∣ab \mid a, since a remainder of zero means aa is a perfect multiple of bb.

In most programming languages this operator is written as %, but that symbol is never used for this purpose in actual mathematics.

Example. Find 19 mod 419 \bmod 4, −11 mod 5-11 \bmod 5 and 333 mod 3333 \bmod 3.
For each one, write out the Division Theorem and read off the remainder;

19=4×4+3⇒19 mod 4=3,−11=−3×5+4⇒−11 mod 5=4,333=111×3+0⇒333 mod 3=0.\begin{align*} 19 &= 4 \times 4 + 3 &&\Rightarrow 19 \bmod 4 = 3, \\ -11 &= -3 \times 5 + 4 &&\Rightarrow -11 \bmod 5 = 4, \\ 333 &= 111 \times 3 + 0 &&\Rightarrow 333 \bmod 3 = 0. \end{align*}

It is important to remember that the remainder is always non-negative, even when aa is negative. It is tempting to say −11 mod 5=−1-11 \bmod 5 = -1, but −1-1 is not a valid remainder; instead we push the quotient one lower (−3-3 rather than −2-2) so that the leftover becomes +4+4. Therefore, 19 mod 4=319 \bmod 4 = 3, −11 mod 5=4-11 \bmod 5 = 4 and 333 mod 3=0333 \bmod 3 = 0.

Modular Congruence#

We just saw that 19 mod 4=319 \bmod 4 = 3, and of course there are infinitely many integers xx satisfying x mod 4=3x \bmod 4 = 3 (namely …,−5,−1,3,7,11,…,19,…,47,…\dots, -5, -1, 3, 7, 11, \dots, 19, \dots, 47, \dots). All of these numbers have something in common, so we say they belong to the same equivalence class. Instead of writing something clunky like 19 mod 4=47 mod 419 \bmod 4 = 47 \bmod 4, we use a special congruence notation, 19≡47(mod4)19 \equiv 47 \pmod 4.

Note

Definition
Given integers aa and bb and a positive integer mm, we say that aa and bb are congruent modulo mm and write

a≡b(modm)a \equiv b \pmod{m}

to mean that a mod m=b mod ma \bmod m = b \bmod m.

Basically, two numbers are congruent modulo mm if they land on the same spot when you wrap the number line around a circle of circumference mm; think of a clock, where 13 o'clock and 1 o'clock are the same thing because 13≡1(mod12)13 \equiv 1 \pmod{12}.

Note

Theorem
The following statements are all equivalent:

  1. a≡b(modm)a \equiv b \pmod m.
  2. a mod m=b mod ma \bmod m = b \bmod m.
  3. aa and bb have the same remainder when divided by mm.
  4. a=b+mka = b + mk for some integer kk.
  5. m∣(a−b)m \mid (a-b).

Proof. Statements (1), (2) and (3) all say the same thing by definition, so it is enough to show that (3) ⇒\Rightarrow (4) ⇒\Rightarrow (5) ⇒\Rightarrow (3), looping back around.

(3) ⇒\Rightarrow (4): Suppose aa and bb leave the same remainder rr; then by the Division Theorem,

a=q1m+r,b=q2m+r,a−b=(q1−q2)m, (subtracting the two equations),a=b+mk, where k=q1−q2∈Z.\begin{align*} a &= q_1 m + r, \\ b &= q_2 m + r, \\ a - b &= (q_1 - q_2)m, \text{ (subtracting the two equations)}, \\ a &= b + mk, \text{ where } k = q_1 - q_2 \in \mathbb{Z}. \end{align*}

(4) ⇒\Rightarrow (5): If a=b+mka = b + mk, then a−b=mka - b = mk, which is precisely the definition of m∣(a−b)m \mid (a-b).

(5) ⇒\Rightarrow (3): Suppose m∣(a−b)m \mid (a - b), and write a=q1m+r1a = q_1 m + r_1 and b=q2m+r2b = q_2 m + r_2 where 0≤r1,r2<m0 \leq r_1, r_2 < m. Then

a−b=(q1−q2)m+(r1−r2).\begin{align*} a - b &= (q_1 - q_2)m + (r_1 - r_2). \end{align*}

Since mm divides both a−ba-b and (q1−q2)m(q_1-q_2)m, it must also divide their difference r1−r2r_1 - r_2. But −m<r1−r2<m-m < r_1 - r_2 < m, and the only multiple of mm strictly between −m-m and mm is 00; hence r1=r2r_1 = r_2. ■\blacksquare

The last characterisation is by far the most useful one in practice:

a≡b(modm)  ⟺  m∣(a−b).\boxed{a \equiv b \pmod m \iff m \mid (a-b).}

Example. Is it true that 47≡19(mod4)47 \equiv 19 \pmod 4?
Rather than computing both remainders separately, just subtract and test divisibility;

47−19=28=4×7,\begin{align*} 47 - 19 &= 28 \\ &= 4 \times 7, \end{align*}

so 4∣(47−19)4 \mid (47-19). Therefore, 47≡19(mod4)47 \equiv 19 \pmod 4. Notice how checking m∣(a−b)m \mid (a-b) only needs one division, so it's usually the fastest way to verify a congruence.

Congruence is an Equivalence Relation#

Note

Lemma
Congruence modulo mm is an equivalence relation on Z\mathbb{Z}. That is, for all a,b,c∈Za,b,c \in \mathbb{Z}:

  • (Reflexive) a≡a(modm)a \equiv a \pmod m.
  • (Symmetric) If a≡b(modm)a \equiv b \pmod m, then b≡a(modm)b \equiv a \pmod m.
  • (Transitive) If a≡b(modm)a \equiv b \pmod m and b≡c(modm)b \equiv c \pmod m, then a≡c(modm)a \equiv c \pmod m.

Reflexivity and symmetry are pretty self explanatory so I'm not gonna write much; m∣(a−a)=0m \mid (a - a) = 0 since everything divides 00, and if m∣(a−b)m \mid (a-b) then m∣−(a−b)=(b−a)m \mid -(a-b) = (b-a). For transitivity, we know m∣(a−b)m \mid (a - b) and m∣(b−c)m \mid (b-c), and since divisibility is preserved under sums,

m∣(a−b)+(b−c)m∣(a−c).\begin{align*} m &\mid (a-b) + (b-c) \\ m &\mid (a - c). \end{align*}

This is exactly why congruence behaves so much like ordinary equality; it slices Z\mathbb{Z} up into mm equivalence classes (one for each possible remainder), and ≡\equiv acts like "==" between the classes.

Properties of Modular Arithmetic#

Note

Theorem
Suppose a,b,c,d∈Za,b,c,d \in \mathbb{Z} and m∈Z+m \in \mathbb{Z}^+. Then:

  1. If a≡b(modm)a \equiv b \pmod m, and k∈Z+k \in \mathbb{Z}^+ satisfies k∣mk \mid m, then a≡b(modk)a \equiv b \pmod k.
  2. If a≡b(modm)a \equiv b \pmod m and c≡d(modm)c \equiv d \pmod m, then a+c≡b+d(modm)a + c \equiv b + d \pmod m.
  3. If a≡b(modm)a \equiv b \pmod m, then a+k≡b+k(modm)a + k \equiv b + k \pmod m for all k∈Zk \in \mathbb{Z}.
  4. If a≡b(modm)a \equiv b \pmod m and c≡d(modm)c \equiv d \pmod m, then ac≡bd(modm)ac \equiv bd \pmod m.
  5. If a≡b(modm)a \equiv b \pmod m, then ak≡bk(modm)ak \equiv bk \pmod m for all k∈Zk \in \mathbb{Z}.
  6. If a≡b(modm)a \equiv b \pmod m, then ak≡bk(modmk)ak \equiv bk \pmod{mk} for all k∈Z+k \in \mathbb{Z}^+.
  7. If ak≡bk(modmk)ak \equiv bk \pmod{mk} for some k∈Z+k \in \mathbb{Z}^+, then a≡b(modm)a \equiv b \pmod m.
  8. If ak≡bk(modm)ak \equiv bk \pmod{m} for some k∈Zk \in \mathbb{Z}, and gcd⁡(m,k)=1\gcd(m,k) = 1, then a≡b(modm)a \equiv b \pmod m.
  9. If a≡b(modm)a \equiv b \pmod m, then ak≡bk(modm)a^k \equiv b^k \pmod m for all k∈Z+k \in \mathbb{Z}^+.

Basically, congruences can be added, subtracted and multiplied together just like ordinary equations, and both sides can be raised to a positive power (property 9 is just property 4 applied to itself kk times). Property 1 says a congruence survives shrinking the modulus to any of its divisors; for instance 26≡14(mod12)26 \equiv 14 \pmod{12}, and since 6∣126 \mid 12, we also get 26≡14(mod6)26 \equiv 14 \pmod 6 for free (both leave remainder 22).

The odd ones out are properties 7 and 8, which are the only two ways to cancel. You cannot freely divide both sides of a congruence; cancellation is only allowed if you also divide the modulus by the same factor (property 7), or if the factor being cancelled is coprime with the modulus (property 8).

We prove two of these; the rest follow from very similar arguments.

Proof (property 4). Since a≡b(modm)a \equiv b \pmod m and c≡d(modm)c \equiv d \pmod m, we can write a=b+mka = b + mk and c=d+mℓc = d + m\ell for some k,ℓ∈Zk, \ell \in \mathbb{Z}. Then

ac=(b+mk)(d+mℓ)=bd+bmℓ+mkd+m2kℓ=bd+m(bℓ+kd+mkℓ).\begin{align*} ac &= (b + mk)(d + m\ell) \\ &= bd + bm\ell + mkd + m^2 k\ell \\ &= bd + m(b\ell + kd + mk\ell). \end{align*}

Since bℓ+kd+mkℓ∈Zb\ell + kd + mk\ell \in \mathbb{Z}, we have m∣(ac−bd)m \mid (ac - bd), and hence ac≡bd(modm)ac \equiv bd \pmod m. ■\blacksquare

Proof (property 8). Since ak≡bk(modm)ak \equiv bk \pmod m, we know that

m∣(ak−bk)m∣(a−b)k.\begin{align*} m &\mid (ak - bk) \\ m &\mid (a-b)k. \end{align*}

Because gcd⁡(m,k)=1\gcd(m,k) = 1, we can write mx+ky=1mx + ky = 1 for some x,y∈Zx,y \in \mathbb{Z} (the gcd is always an integer linear combination, via the extended Euclidean algorithm). Multiplying through by a−ba - b,

a−b=(a−b)mx+(a−b)ky.\begin{align*} a - b &= (a-b)mx + (a-b)ky. \end{align*}

Now mm divides the first term (it contains a factor of mm), and mm divides the second term (since m∣(a−b)km \mid (a-b)k). Therefore m∣(a−b)m \mid (a - b), i.e. a≡b(modm)a \equiv b \pmod m. ■\blacksquare

Example. Find (123×456+789) mod 11(123 \times 456 + 789) \bmod 11.
The whole point of properties 2 and 4 is that we can reduce every number before doing any arithmetic, instead of multiplying huge numbers together. Reducing each term modulo 1111;

123=11×11+2⇒123≡2(mod11),456=41×11+5⇒456≡5(mod11),789=71×11+8⇒789≡8(mod11).\begin{align*} 123 &= 11 \times 11 + 2 &&\Rightarrow 123 \equiv 2 \pmod{11}, \\ 456 &= 41 \times 11 + 5 &&\Rightarrow 456 \equiv 5 \pmod{11}, \\ 789 &= 71 \times 11 + 8 &&\Rightarrow 789 \equiv 8 \pmod{11}. \end{align*}

Then,

123×456+789≡2×5+8(mod11)≡10+8(mod11)≡18(mod11)≡7(mod11).\begin{align*} 123 \times 456 + 789 &\equiv 2 \times 5 + 8 \pmod{11} \\ &\equiv 10 + 8 \pmod{11} \\ &\equiv 18 \pmod{11} \\ &\equiv 7 \pmod{11}. \end{align*}

Therefore, (123×456+789) mod 11=7(123 \times 456 + 789) \bmod 11 = 7; we never had to touch a number bigger than 1818.

Example. It is true that 6≡2(mod4)6 \equiv 2 \pmod 4. Can we cancel the common factor of 22 to conclude that 3≡1(mod4)3 \equiv 1 \pmod 4?
No! Checking directly,

3−1=2,4∤2,\begin{align*} 3 - 1 &= 2, \\ 4 &\nmid 2, \end{align*}

so 3≢1(mod4)3 \not\equiv 1 \pmod 4; naive cancelling produced a false statement. The problem is that gcd⁡(2,4)=2≠1\gcd(2, 4) = 2 \neq 1, so property 8 does not apply. What we are allowed to do is property 7, dividing the two sides and the modulus by 22;

6≡2(mod4)3≡1(mod2),\begin{align*} 6 &\equiv 2 \pmod 4 \\ 3 &\equiv 1 \pmod 2, \end{align*}

which is true, since 33 and 11 are both odd. Therefore, before cancelling a factor kk from a congruence, always check gcd⁡(m,k)\gcd(m,k) first; if kk shares a factor with the modulus, that factor must be divided out of the modulus too.

The Set of Integers Modulo m#

Since congruence modulo mm behaves so much like equality, we can build an entire self-contained number system out of it.

Note

Definition
Given any positive integer mm, the ring of integers modulo mm is denoted Zm\mathbb{Z}_m, and is the number system with elements {0,1,2,…,m−1}\{0, 1, 2, \dots, m-1\} and addition and multiplication operations the same as in Z\mathbb{Z}, except always reduced to the smallest non-negative remainder modulo mm.
(Zm\mathbb{Z}_m is also sometimes written as Z/mZ\mathbb{Z}/m\mathbb{Z}.)

Basically, Zm\mathbb{Z}_m is clock arithmetic; only the mm numbers 00 to m−1m-1 exist, and everything else wraps around. We may write "a=ba = b in Zm\mathbb{Z}_m" to mean exactly the same thing as congruence modulo m. For example, the following statements are all valid:

  • 19=319 = 3 in Z4\mathbb{Z}_4.
  • 19=−1=419 = -1 = 4 in Z5\mathbb{Z}_5.
  • Working in Z7\mathbb{Z}_7, we have 699=−1=6699 = -1 = 6 (since 700=7×100700 = 7 \times 100).

Notice how useful the negative representatives are; being allowed to swap 699699 for −1-1 in Z7\mathbb{Z}_7 means we can trade a big ugly number for a tiny one, which makes taking powers almost trivial.

Example. Show that 41004^{100} leaves a remainder of 11 when divided by 55.
Since 4≡−1(mod5)4 \equiv -1 \pmod 5, property 9 lets us replace the base 44 with −1-1 before taking the power, and (−1)100=1(-1)^{100} = 1 because 100100 is even. Here are three ways of writing the exact same proof:

  • 4100 mod 5=(−1)100 mod 5=1 mod 5=14^{100} \bmod 5 = (-1)^{100} \bmod 5 = 1 \bmod 5 = 1.
  • 4100≡(−1)100≡1(mod5)4^{100} \equiv (-1)^{100} \equiv 1 \pmod 5.
  • 4100=(−1)100=14^{100} = (-1)^{100} = 1 in Z5\mathbb{Z}_5.

Therefore, 4100 mod 5=14^{100} \bmod 5 = 1; all three notations are interchangeable, so use whichever is cleanest for the question at hand.

Reducing Powers Modulo m#

Finding large powers aka^k in Zm\mathbb{Z}_m is difficult, because you are allowed to reduce the base aa modulo mm, but you can NEVER reduce the exponent kk modulo mm. As a quick counterexample, take 242^4 in Z3\mathbb{Z}_3; reducing the exponent 4 mod 3=14 \bmod 3 = 1 would suggest 24≡21(mod3)2^4 \equiv 2^1 \pmod 3, but

24=16≡1(mod3),21≡2(mod3),\begin{align*} 2^4 = 16 &\equiv 1 \pmod 3, \\ 2^1 &\equiv 2 \pmod 3, \end{align*}

which are clearly not the same. The exponent counts how many times we multiply; it is not itself a number living in Zm\mathbb{Z}_m.

Instead, the trick is to hunt for a small power of aa that reduces to something close to 00 in Zm\mathbb{Z}_m (ideally 11 or −1-1), and then use the Division Theorem on the exponent;

If aj≡±1(modm) and k=qj+r, then ak=(aj)q⋅ar≡(±1)q ar(modm).\boxed{\text{If } a^j \equiv \pm 1 \pmod m \text{ and } k = qj + r, \text{ then } a^k = (a^j)^q \cdot a^r \equiv (\pm 1)^q \, a^r \pmod m.}

Example. Find 71001 mod 127^{1001} \bmod 12.
Try small powers of 77 in Z12\mathbb{Z}_{12};

72=49=4×12+1≡1(mod12),\begin{align*} 7^2 &= 49 \\ &= 4 \times 12 + 1 \\ &\equiv 1 \pmod{12}, \end{align*}

so we found a power congruent to 11 almost immediately. Splitting the exponent as 1001=2×500+11001 = 2 \times 500 + 1,

71001=(72)500×71≡1500×7(mod12)≡7(mod12).\begin{align*} 7^{1001} &= (7^2)^{500} \times 7^1 \\ &\equiv 1^{500} \times 7 \pmod{12} \\ &\equiv 7 \pmod{12}. \end{align*}

Therefore, 71001 mod 12=77^{1001} \bmod 12 = 7.

Example. Find 121001 mod 712^{1001} \bmod 7.
First reduce the base; 12≡5≡−2(mod7)12 \equiv 5 \equiv -2 \pmod 7, and −2-2 is the smaller (in size) representative, so work with that. Trying small powers of −2-2,

(−2)2=4≡4(mod7),(−2)3=−8≡−1(mod7),\begin{align*} (-2)^2 &= 4 \equiv 4 \pmod 7, \\ (-2)^3 &= -8 \equiv -1 \pmod 7, \end{align*}

so the cube gets us to −1-1. Splitting the exponent as 1001=3×333+21001 = 3 \times 333 + 2,

121001≡(−2)1001(mod7)=((−2)3)333×(−2)2≡(−1)333×4(mod7)≡−4(mod7)≡3(mod7).\begin{align*} 12^{1001} &\equiv (-2)^{1001} \pmod 7 \\ &= \left((-2)^3\right)^{333} \times (-2)^2 \\ &\equiv (-1)^{333} \times 4 \pmod 7 \\ &\equiv -4 \pmod 7 \\ &\equiv 3 \pmod 7. \end{align*}

Therefore, 121001 mod 7=312^{1001} \bmod 7 = 3. Don't forget the very last step; the mod operator demands a remainder between 00 and 66, so −4-4 must be converted to 33 before you write down the final answer.

Example. Find 51001 mod 935^{1001} \bmod 93.
Small powers of 55 don't immediately give ±1\pm 1 here, but keep going;

52=25≡25(mod93),53=125=93+32≡32(mod93),56=(53)2≡322=1024(mod93),\begin{align*} 5^2 &= 25 \equiv 25 \pmod{93}, \\ 5^3 &= 125 = 93 + 32 \equiv 32 \pmod{93}, \\ 5^6 &= (5^3)^2 \equiv 32^2 = 1024 \pmod{93}, \end{align*}

and since 1024=11×93+11024 = 11 \times 93 + 1, we get 56≡1(mod93)5^6 \equiv 1 \pmod{93}. Splitting the exponent as 1001=6×166+51001 = 6 \times 166 + 5,

51001=(56)166×55≡1166×53×52(mod93)≡32×25(mod93)≡800(mod93)≡800−8×93(mod93)≡56(mod93).\begin{align*} 5^{1001} &= (5^6)^{166} \times 5^5 \\ &\equiv 1^{166} \times 5^3 \times 5^2 \pmod{93} \\ &\equiv 32 \times 25 \pmod{93} \\ &\equiv 800 \pmod{93} \\ &\equiv 800 - 8 \times 93 \pmod{93} \\ &\equiv 56 \pmod{93}. \end{align*}

Therefore, 51001 mod 93=565^{1001} \bmod 93 = 56. We will see some more efficient ways to reduce powers modulo mm in Topic 5.

When No Power Reduces to 1#

Sometimes the "find aj≡±1a^j \equiv \pm 1" strategy is doomed from the start. If gcd⁡(a,m)≠1\gcd(a, m) \neq 1, then every power of aa shares that common factor with mm, so no power of aa can ever be congruent to 11 or −1-1. In that case, look for a repeating cycle in the powers instead.

Example. Find 3103 mod 153^{103} \bmod 15.
Here gcd⁡(3,15)=3≠1\gcd(3,15) = 3 \neq 1, so every power of 33 is a multiple of 33 in Z15\mathbb{Z}_{15}, and neither 11 nor 1414 is; hunting for ±1\pm 1 would be a waste of time. Instead, list the powers and wait for a repeat;

31≡3(mod15),32≡9(mod15),33=27≡12(mod15),34=81≡6(mod15),35=243≡3(mod15).\begin{align*} 3^1 &\equiv 3 \pmod{15}, \\ 3^2 &\equiv 9 \pmod{15}, \\ 3^3 = 27 &\equiv 12 \pmod{15}, \\ 3^4 = 81 &\equiv 6 \pmod{15}, \\ 3^5 = 243 &\equiv 3 \pmod{15}. \end{align*}

Since 35≡313^5 \equiv 3^1, the powers cycle with period 44 from exponent 11 onwards; multiplying both sides by 33 repeatedly gives 3k+4≡3k(mod15)3^{k+4} \equiv 3^k \pmod{15} for all k≥1k \geq 1. So we can strip multiples of 44 off the exponent (as long as we stop before reaching 00);

3103≡3103−4×25(mod15)≡33(mod15)≡12(mod15).\begin{align*} 3^{103} &\equiv 3^{103 - 4 \times 25} \pmod{15} \\ &\equiv 3^3 \pmod{15} \\ &\equiv 12 \pmod{15}. \end{align*}

Therefore, 3103 mod 15=123^{103} \bmod 15 = 12. Note the subtlety: the cycle starts at exponent 11, not 00 (30=13^0 = 1 is not part of the loop), so we reduce the exponent using the cycle we found, never by blindly taking 103 mod 4103 \bmod 4 and allowing exponent 00.

Alternate solution. We can also exploit property 6 from the properties of modular arithmetic. Write 3103=3×31023^{103} = 3 \times 3^{102} and 15=3×515 = 3 \times 5; then it is enough to find 31023^{102} in Z5\mathbb{Z}_5, where gcd⁡(3,5)=1\gcd(3,5)=1 so the usual trick works;

32=9≡−1(mod5),3102=(32)51≡(−1)51(mod5)≡−1(mod5)≡4(mod5).\begin{align*} 3^2 = 9 &\equiv -1 \pmod 5, \\ 3^{102} = (3^2)^{51} &\equiv (-1)^{51} \pmod 5 \\ &\equiv -1 \pmod 5 \\ &\equiv 4 \pmod 5. \end{align*}

Now multiply both sides and the modulus by 33 (property 6 with k=3k = 3);

3102≡4(mod5)3×3102≡3×4(mod15)3103≡12(mod15).\begin{align*} 3^{102} &\equiv 4 \pmod 5 \\ 3 \times 3^{102} &\equiv 3 \times 4 \pmod{15} \\ 3^{103} &\equiv 12 \pmod{15}. \end{align*}

Therefore, 3103 mod 15=123^{103} \bmod 15 = 12, agreeing with the first method. The decision here is worth remembering; when the base shares a factor with the modulus, either find the cycle directly, or factor that common divisor out and work in the smaller coprime modulus.

Applications of Modular Arithmetic#

These kinds of questions rarely announce themselves as "modular arithmetic"; the skill is recognising that some quantity wraps around with a fixed period, and choosing the right modulus.

Last Digit Problems#

The last digit of a number is exactly its remainder modulo 1010 (this drops straight out of the base 1010 representation, since every higher digit is multiplied by a power of 1010, and 10≡0(mod10)10 \equiv 0 \pmod{10}).

Example. Find the last digit of 720267^{2026}.
We want 72026 mod 107^{2026} \bmod 10. Hunting for small powers of 77 in Z10\mathbb{Z}_{10},

72=49≡−1(mod10),\begin{align*} 7^2 &= 49 \\ &\equiv -1 \pmod{10}, \end{align*}

and since 2026=2×10132026 = 2 \times 1013,

72026=(72)1013≡(−1)1013(mod10)≡−1(mod10)≡9(mod10).\begin{align*} 7^{2026} &= (7^2)^{1013} \\ &\equiv (-1)^{1013} \pmod{10} \\ &\equiv -1 \pmod{10} \\ &\equiv 9 \pmod{10}. \end{align*}

Therefore, the last digit of 720267^{2026} is 99.

Day of the Week Problems#

Days of the week repeat with period 77, so any "what day will it be" question is just arithmetic in Z7\mathbb{Z}_7.

Example. Today is a Thursday. What day of the week will it be 10001000 days from now?
Reduce the number of days modulo 77;

1000=142×7+6≡6(mod7).\begin{align*} 1000 &= 142 \times 7 + 6 \\ &\equiv 6 \pmod 7. \end{align*}

So 10001000 days is 142142 complete weeks (which change nothing) plus 66 extra days, and counting six days on from Thursday lands on Wednesday. Even quicker, notice that 6≡−1(mod7)6 \equiv -1 \pmod 7; going forward 10001000 days is the same as going back one day, i.e. the day before Thursday. Therefore, 10001000 days from now it will be a Wednesday.

Divisibility Tests via Digit Sums#

Since 10≡1(mod9)10 \equiv 1 \pmod 9, property 9 gives 10k≡1k≡1(mod9)10^k \equiv 1^k \equiv 1 \pmod 9 for every k∈Z+k \in \mathbb{Z}^+; so in Z9\mathbb{Z}_9, every number collapses down to the sum of its digits. This is exactly where the "divisible by 9 if its digit sum is" test comes from (and the same works modulo 33, since 10≡1(mod3)10 \equiv 1 \pmod 3 too).

Example. Is 7654321876543218 divisible by 99?
Expanding in base 1010 and reducing each power of 1010 to 11,

76543218=7×107+6×106+5×105+4×104+3×103+2×102+1×10+8≡7+6+5+4+3+2+1+8(mod9)≡36(mod9)≡0(mod9).\begin{align*} 76543218 &= 7 \times 10^7 + 6 \times 10^6 + 5 \times 10^5 + 4 \times 10^4 + 3 \times 10^3 + 2 \times 10^2 + 1 \times 10 + 8 \\ &\equiv 7 + 6 + 5 + 4 + 3 + 2 + 1 + 8 \pmod 9 \\ &\equiv 36 \pmod 9 \\ &\equiv 0 \pmod 9. \end{align*}

Therefore, 9∣765432189 \mid 76543218; the number is divisible by 99 because its digit sum is.

Showing a Number is Not a Perfect Square#

A classic exam trick is to rule something out by reducing modulo a small number and checking which residues are even possible.

Example. Show that 218745983218745983 is not a perfect square.
Work in Z4\mathbb{Z}_4. Every integer nn is congruent to one of 0,1,2,30,1,2,3 modulo 44, so by property 9 there are only four cases for n2n^2;

02≡0(mod4),12≡1(mod4),22=4≡0(mod4),32=9≡1(mod4).\begin{align*} 0^2 &\equiv 0 \pmod 4, \\ 1^2 &\equiv 1 \pmod 4, \\ 2^2 = 4 &\equiv 0 \pmod 4, \\ 3^2 = 9 &\equiv 1 \pmod 4. \end{align*}

So every perfect square is congruent to 00 or 11 modulo 44; a square can never be 22 or 33 in Z4\mathbb{Z}_4. Now, since 100≡0(mod4)100 \equiv 0 \pmod 4, any number is congruent modulo 44 to just its last two digits, hence

218745983≡83(mod4)≡3(mod4), (as 83=20×4+3).\begin{align*} 218745983 &\equiv 83 \pmod 4 \\ &\equiv 3 \pmod 4, \text{ (as } 83 = 20 \times 4 + 3). \end{align*}

Since 33 is not an achievable residue for a square, 218745983218745983 cannot be a perfect square. Therefore, we ruled it out without computing a single square root; picking a small modulus and eliminating impossible residues is often far faster than direct computation.