Modular Arithmetic: Remainders, Congruences, and Competition Methods

A progressive guide to modular arithmetic, from remainders and congruences through powers, divisibility, systems of congruences, inverses, and advanced competition methods.

Remainders and the

Modular arithmetic focuses on what remains after division rather than on the full size of a number.

For positive integers aa and nn, write

a=qn+r,0≤r<n.a=qn+r, \qquad 0\le r<n.

The value rr is the , and the notation a mod na\bmod n asks for that . For example,

17=5⋅3+2,17 mod 5=2.17=5\cdot3+2, \qquad 17\bmod5=2.

The divisor nn is the . When dividing by 55, the only possible standard remainders are 0,1,2,3,40,1,2,3,4. A cannot be at least the , because another copy of the could still be removed.

A useful calculation routine is:

  1. Find the largest multiple of the that does not exceed the number.

  2. Subtract that multiple.

  3. Check that the result lies between 00 and one less than the .

For instance,

100=12⋅8+4,100 mod 12=4.100=12\cdot8+4, \qquad 100\bmod12=4.

Special cases are worth recognizing. If 0<a<n0<a<n, then a mod n=aa\bmod n=a. If n∣an\mid a, then a mod n=0a\bmod n=0.

and Classes

compares behavior. The statement

a≡b(modn)a\equiv b\pmod n

means that aa and bb have the same when divided by nn. Equivalently,

a≡b(modn)⟺n∣(a−b).a\equiv b\pmod n \quad\Longleftrightarrow\quad n\mid(a-b).

For example,

17≡5(mod6)17\equiv5\pmod6

because 17−5=1217-5=12, which is divisible by 66. The same fact can be checked through remainders: both numbers leave 55 modulo 66.

Do not confuse a modulo result with a . The statement

17 mod 6=517\bmod6=5

identifies the actual standard , whereas

17≡5(mod6)17\equiv5\pmod6

places 1717 and 55 in the same class modulo 66. The numbers 2,7,12,17,…2,7,12,17,\ldots are all congruent modulo 55, because each leaves 22.

A reliable way to verify a is to subtract the two sides and test divisibility by the . Remember that is not ordinary equality: 1717 and 55 are different integers even though they are congruent modulo 66.

Arithmetic with Congruences

Congruences can be added, subtracted, and multiplied. If

a≡r(modm)andb≡s(modm),a\equiv r\pmod m \qquad\text{and}\qquad b\equiv s\pmod m,

then

a+b≡r+s(modm),a+b\equiv r+s\pmod m,
a−b≡r−s(modm),a-b\equiv r-s\pmod m,
ab≡rs(modm).ab\equiv rs\pmod m.

Reduce the final result to a standard when a numerical answer is requested.

For example, to find 37⋅24(mod5)37\cdot24\pmod5, reduce first:

37≡2a(mod5),24≡4a(mod5).37\equiv2 a\pmod5, \qquad 24\equiv4 a\pmod5.

Thus,

37⋅24≡2⋅4=8≡3(mod5).37\cdot24\equiv2\cdot4=8\equiv3\pmod5.

Subtraction may produce a negative intermediate value. For example,

14−39≡3−6=−3≡8(mod11).14-39\equiv3-6=-3\equiv8\pmod{11}.

The standard is 88, obtained by adding 1111 to −3-3. More generally, add or subtract the until the result lies in the range from 00 through m−1m-1.

These rules make large expressions manageable. For

(58+76)⋅19(mod10),(58+76)\cdot19\pmod{10},

replace the numbers by 88, 66, and 99:

(58+76)⋅19≡(8+6)⋅9=126≡6(mod10).(58+76)\cdot19\equiv(8+6)\cdot9=126\equiv6\pmod{10}.

A key caution is division. Addition, subtraction, and multiplication preserve directly, but cancellation requires a and therefore a relatively prime factor.

Choosing Moduli for Divisibility and Parity

Choose a that matches the information being asked for.

  • Use modulo 22 for parity: even numbers satisfy n≡0(mod2)n\equiv0\pmod2, and odd numbers satisfy n≡1(mod2)n\equiv1\pmod2.

  • Use modulo 33 or modulo 99 for digit-sum tests.

  • Use modulo 44 for the last two digits.

  • Use modulo 88 for the last three digits.

  • Use modulo 1010 for the last digit.

  • Use modulo 1111 for alternating digit sums.

For a decimal number, powers of 1010 simplify under these moduli. Since 10≡1(mod9)10\equiv1\pmod9, a number and its digit sum have the same modulo 99. For example,

472≡4+7+2=13≡4a(mod9).472\equiv4+7+2=13\equiv4 a\pmod9.

Parity often gives a fast contradiction. Three odd integers have sum congruent to

1+1+1=3≡1a(mod2),1+1+1=3\equiv1 a\pmod2,

so their sum cannot be even.

For several conditions, translate each sentence into a . For example, “leaves 22 when divided by 33” becomes x≡2(mod3)x\equiv2\pmod3, while “is divisible by 55” becomes x≡0(mod5)x\equiv0\pmod5. Then list candidates, substitute, or combine the conditions systematically.

Always check compatibility first when moduli share a factor. A number satisfying x≡2(mod4)x\equiv2\pmod4 is even, while a number satisfying x≡3(mod6)x\equiv3\pmod6 is odd; therefore, those two conditions cannot hold simultaneously.

Powers, Cycles, and Digit Problems

Powers often have repeating patterns. To find the last digit of a power, work modulo 1010. The powers of 77 have last-digit cycle

7,9,3,1.7,9,3,1.

Because the cycle length is 44,

2026≡2a(mod4),2026\equiv2 a\pmod4,

so

72026≡72≡9a(mod10).7^{2026}\equiv7^2\equiv9 a\pmod{10}.

A of 00 when reducing an exponent by a cycle length means use the last entry of the cycle, not the first. For example, the exponent 100100 is congruent to 00 modulo 44, so 71007^{100} corresponds to the fourth cycle entry, namely 11.

For a large exponent, use one of three approaches:

  1. Calculate successive powers until a cycle appears.

  2. Use and reduce after each multiplication.

  3. Apply a theorem such as or Euler's theorem when its conditions hold.

is efficient because an exponent can be written as a sum of powers of 22. For example, 100=64+32+4100=64+32+4, so compute a64a^{64}, a32a^{32}, and a4a^4 by successive squaring, then multiply their reduced residues.

says that for a prime pp with p∤ap\nmid a,

ap−1≡1a(modp).a^{p-1}\equiv1 a\pmod p.

Thus, for 2100(mod13)2^{100}\pmod{13}, reduce the exponent modulo 1212:

100=12⋅8+4,2100≡24ototagequiv3ototaga(mod13).100=12\cdot8+4, \qquad 2^{100}\equiv2^4 ot otag equiv3 ot otag a\pmod{13}.

The condition p∤ap\nmid a is essential. Do not reduce exponents automatically without checking the relevant cycle or theorem.

Combining Conditions

A system of congruences can often be solved by listing candidates or by substitution. Consider

x≡2a(mod3),x≡4a(mod5).x\equiv2 a\pmod3, \qquad x\equiv4 a\pmod5.

Numbers congruent to 22 modulo 33 are 2,5,8,11,14,…2,5,8,11,14,\ldots. The first one that is congruent to 44 modulo 55 is 1414, so

x≡14a(mod15).x\equiv14 a\pmod{15}.

The period is 1515 because 33 and 55 are relatively prime.

Substitution gives another method. To solve

x≡1a(mod4),x≡3a(mod5),x\equiv1 a\pmod4, \qquad x\equiv3 a\pmod5,

write x=1+4kx=1+4k. Then

1+4k≡3otaga(mod5),4k≡2otaga(mod5).1+4k\equiv3 otag a\pmod5, \qquad 4k\equiv2 otag a\pmod5.

Since 4≡−1(mod5)4\equiv-1\pmod5, we obtain k≡3(mod5)k\equiv3\pmod5, and therefore x=13x=13 is the least positive solution. The complete solution is

x≡13otaga(mod20).x\equiv13 otag a\pmod{20}.

This is an instance of the : compatible conditions with relatively prime moduli determine one residue modulo the product of the moduli. If moduli share factors, the corresponding remainders must agree modulo the common factors.

For a

ax≡botaga(modm),ax\equiv b otag a\pmod m,

let d=gcd⁡(a,m)d=\gcd(a,m). If d∤bd\nmid b, there are no solutions. If d∣bd\mid b, divide the entire by dd, solve the reduced , and then account for the resulting solution classes modulo mm.

Modular Inverses and Safe Division

Division in modular arithmetic means multiplication by a . An inverse of aa modulo mm is a number a−1a^{-1} satisfying

aa−1≡1otaga(modm).aa^{-1}\equiv1 otag a\pmod m.

Such an inverse exists exactly when gcd⁡(a,m)=1\gcd(a,m)=1. For example, 3−1≡5(mod7)3^{-1}\equiv5\pmod7 because 3⋅5=15≡1(mod7)3\cdot5=15\equiv1\pmod7. Therefore, solving

3x≡4otaga(mod7)3x\equiv4 otag a\pmod7

gives

x≡5otaga⋅4=20≡6otaga(mod7).x\equiv5 otag a\cdot4=20\equiv6 otag a\pmod7.

If the coefficient and are not relatively prime, cancellation may be invalid. From 2x≡2otaga(mod6)2x\equiv2 otag a\pmod6, it does not follow that x≡1otaga(mod6)x\equiv1 otag a\pmod6. The original has more than one solution class.

The Euclidean algorithm can find inverses. For instance,

43=2⋅17+9,17=9+8,9=8+1.43=2\cdot17+9, \qquad 17=9+8, \qquad 9=8+1.

Working backward gives

1=2⋅43−5⋅17,1=2\cdot43-5\cdot17,

so −5-5 and 3838 are inverses of 1717 modulo 4343. This allows the equation

17x≡5otaga(mod43)17x\equiv5 otag a\pmod{43}

to be solved as

x≡5⋅38=190≡18otaga(mod43).x\equiv5\cdot38=190\equiv18 otag a\pmod{43}.

For a prime pp, also gives

a−1otaga≡ap−2otaga(modp)a^{-1} otag a\equiv a^{p-2} otag a\pmod p

when p∤ap\nmid a. Use the Euclidean algorithm for small direct computations, and use exponentiation when powers are already part of the problem.

Advanced Competition Methods

Factorials and products often simplify through divisibility. If a factorial contains enough factors to include every prime factor of the with sufficient multiplicity, its is 00. For example,

50!=1⋅2⋅…⋅5050!=1\cdot2\cdot\ldots\cdot50

contains both 33 and 1717, so it contains a factor of 51=3⋅1751=3\cdot17. Hence

50!≡0otaga(mod51).50!\equiv0 otag a\pmod{51}.

For a prime pp, states

(p−1)!otaga≡−1otaga(modp).(p-1)! otag a\equiv-1 otag a\pmod p.

For example,

10!≡−1≡10otaga(mod11).10!\equiv-1\equiv10 otag a\pmod{11}.

A nearby factorial can be related to (p−1)!(p-1)!. Since

100!=98!⋅99⋅100100!=98!\cdot99\cdot100

and 100!≡−1(mod101)100!\equiv-1\pmod{101}, we get

98!⋅(−2)⋅(−1)≡−1otaga(mod101).98!\cdot(-2)\cdot(-1)\equiv-1 otag a\pmod{101}.

Thus, 2⋅98!≡−1(mod101)2\cdot98!\equiv-1\pmod{101}, and multiplying by the inverse of 22 yields 98!≡50otaga(mod101)98!\equiv50 otag a\pmod{101}.

For factorial quotients, simplify the quotient as an ordinary integer before reducing whenever possible. Do not cancel factors inside a unless the canceled factor has a .

A dependable competition workflow is:

  1. Identify the target and factor it if useful.

  2. Inspect factorials and products for immediate divisibility.

  3. Reduce large bases to small congruent values.

  4. Find a cycle or use for powers.

  5. Apply only when its conditions hold.

  6. Replace division with multiplication by a .

  7. Convert negative answers to standard remainders and verify the result.