Discrete MathematicsModular Arithmetic and Cryptography3 of 6
Modular Arithmetic and Cryptography · 3

Modular Inverses and Linear Congruences

To solve an equation like 3x≡2(mod7)\step{3}x \equiv \target{2} \pmod 7 for xx, we need a way to undo multiplying by 3\step{3} on a clock where fractions do not exist.

1

What Is a Modular Inverse?

We want to isolate xx in the linear congruence 3x≡2(mod7)\step{3}x \equiv \target{2} \pmod 7 using only whole numbers on a 77-hour clock.

What Is a Modular Inverse?
00
11
2\htmlClass{lc-pink}{2}
33
44
55
66
3x\htmlClass{lc-blue}{3}x
≡2(mod7){}\equiv \htmlClass{lc-pink}{2} \pmod 7
xx
=?{}= {}?

On a 77-hour clock, there is no fraction 13\inverse{\frac{1}{3}}, so instead we look for the whole number that multiplies with 3\step{3} to land on 1\target{1}:

3⋅5⏟modular inverse 3−1≡1(mod7)\displaystyle \step{3} \cdot \underbrace{\inverse{5}}_{\text{modular inverse } \step{3}^{\inverse{-1}}} \equiv \target{1} \pmod 7

The −1\inverse{-1} exponent in 3−1\step{3}^{\inverse{-1}} means the whole number that turns 3\step{3} into 1\target{1} modulo 77, not the fraction 13\inverse{\frac{1}{3}}.

Text solution
Find the modular inverse of 3\step{3} modulo 77Testing multiples of 3\step{3} on a 77-hour clock shows that 3×5=15\step{3} \times \inverse{5} = 15 is 1\target{1} hour past two full laps of 77:
3⋅5\displaystyle \step{3} \cdot \inverse{5} =15≡1(mod7)  ⟹  3−1≡5(mod7)\displaystyle = 15 \equiv \target{1} \pmod 7 \implies \step{3}^{\inverse{-1}} \equiv \inverse{5} \pmod 7
Multiply both sides of 3x≡2(mod7)\step{3}x \equiv \target{2} \pmod 7 by 5\inverse{5} and reduce modulo 77Multiplying by 5\inverse{5} turns 3x\step{3}x into 15x≡1x15x \equiv 1x and leaves the solution on the right:
5⋅(3x)≡5⋅2(mod7)15x≡10(mod7)x≡3(mod7)\displaystyle \begin{aligned} \inverse{5} \cdot (\step{3}x) &\equiv \inverse{5} \cdot \target{2} \pmod 7 \\ 15x &\equiv 10 \pmod 7 \\ x &\equiv 3 \pmod 7 \end{aligned}
2

When Modular Inverses Exist

On a 77-hour clock, 3\step{3} had an inverse, but on other clocks some multipliers get stuck in a loop and never reach 1\target{1}. We want to know which numbers a\step{a} have a modular inverse on an mm-hour clock.

When Modular Inverses Exist
00
1\htmlClass{lc-pink}{1}
22
33
44
55
66
77
88
99
3×\htmlClass{lc-blue}{3} \times {}
≡1(mod10){}\equiv \htmlClass{lc-pink}{1} \pmod{10}
4×\htmlClass{lc-blue}{4} \times {}
≡1(mod10){}\equiv \htmlClass{lc-pink}{1} \pmod{10}

When gcd⁡(a,m)>1\gcd(\step{a}, m) > 1, steps of size a\step{a} on an mm-hour clock only land on multiples of gcd⁡(a,m)\gcd(\step{a}, m) and skip right over 1\target{1}. When gcd⁡(a,m)=1\gcd(\step{a}, m) = \holds{1}, Bézout's Identity guarantees integers xx and yy that combine a\step{a} and mm to make 1\target{1}, and reducing that equation modulo mm drops the full laps my\laps{my} to leave the inverse x\inverse{x}:

ax+my⏟≡ 0(modm)\displaystyle \step{a}x + \underbrace{\laps{my}}_{\equiv\, 0 \pmod m} =1  ⟹  ax⏟a−1≡1(modm)\displaystyle = \target{1} \implies \step{a}\underbrace{\inverse{x}}_{\step{a}^{\inverse{-1}}} \equiv \target{1} \pmod m
a has an inverse modulo m  ⟺  gcd⁡(a,m)\displaystyle \step{a} \text{ has an inverse modulo } m \iff \gcd(\step{a}, m) =1\displaystyle = \holds{1}

On a 1010-hour clock, step sizes a\step{a} that share a factor with 1010 (2,4,5,6,8\step{2}, \step{4}, \step{5}, \step{6}, \step{8}) stay trapped in multiples of that factor and never reach 1\target{1}, while step sizes with gcd⁡(a,10)=1\gcd(\step{a}, 10) = \holds{1} (1,3,7,9\step{1}, \step{3}, \step{7}, \step{9}) visit every hour and land on 1\target{1} at their modular inverse.

On a 10-hour clock, repeated jumps reach hour 1 only when the step size shares no factor larger than 1 with 10.
3

Finding an Inverse with Bézout's Identity

When the clock is large, testing multiples by hand takes too long, so we use the Euclidean algorithm and Bézout's Identity to find the modular inverse of 17\step{17} modulo 4343, that is, to solve 17x≡1(mod43)\step{17}x \equiv \target{1} \pmod{43}.

Finding an Inverse with Bézout's Identity
17−1≡?(mod43)\displaystyle \step{17}^{\inverse{-1}} \equiv {}? \pmod{43}
Text solution
Run the Euclidean algorithm down to 1\target{1} and solve each row for its remainderDividing 4343 by 17\step{17} and continuing with the remainders reaches gcd⁡(17,43)=1\gcd(\step{17}, 43) = \holds{1} in three steps:
43=2(17)+9  ⟹  9=43−2(17)17=1(9)+8  ⟹  8=17−1(9)9=1(8)+1  ⟹  1=9−1(8)\displaystyle \begin{aligned} 43 &= 2(\step{17}) + \leftover{9} \\ \implies \leftover{9} &= 43 - 2(\step{17}) \\[4pt] \step{17} &= 1(\leftover{9}) + \leftover{8} \\ \implies \leftover{8} &= \step{17} - 1(\leftover{9}) \\[4pt] \leftover{9} &= 1(\leftover{8}) + \target{1} \\ \implies \target{1} &= \leftover{9} - 1(\leftover{8}) \end{aligned}
Back-substitute the remainders to write 1\target{1} as a combination of 4343 and 17\step{17}Replacing 8\leftover{8} and then 9\leftover{9} expresses 1\target{1} in terms of 4343 and 17\step{17}:
1=1(9)−1[17−1(9)]=2(9)−1(17)=2[43−2(17)]−1(17)=2(43)−5(17)\displaystyle \begin{aligned} \target{1} &= 1(\leftover{9}) - 1\bigl[\step{17} - 1(\leftover{9})\bigr] \\ &= 2(\leftover{9}) - 1(\step{17}) \\ &= 2\bigl[43 - 2(\step{17})\bigr] - 1(\step{17}) \\ &= 2(43) - 5(\step{17}) \end{aligned}
Reduce modulo 4343 and convert the inverse to a positive clock numberCrossing out the two full laps 2(43)≡0(mod43)\laps{2(43)} \equiv 0 \pmod{43} leaves −5\inverse{-5} as the inverse of 17\step{17}, and adding 43\laps{43} gives the positive hour on the clock:
1≡2(43)−5(17)(mod43)1≡−5⋅17(mod43)17−1≡−5≡38(mod43)\displaystyle \begin{aligned} \target{1} &\equiv \laps{2(43)} - \inverse{5}(\step{17}) \pmod{43} \\ \target{1} &\equiv \inverse{-5} \cdot \step{17} \pmod{43} \\ \step{17}^{\inverse{-1}} &\equiv \inverse{-5} \equiv \inverse{38} \pmod{43} \end{aligned}
4

Solving Linear Congruences: The Three Cases

Now we want to solve any linear congruence ax≡b(modm)\step{a}x \equiv \target{b} \pmod m for xx. Whether a\step{a} has an inverse, and how many solutions exist on the mm-hour clock, depends on g=gcd⁡(a,m)\shared{g} = \gcd(\step{a}, m), which splits every problem into three cases.

Solving Linear Congruences: The Three Cases
ax≡b(modm)x=?\displaystyle \begin{aligned} \step{a}x &\equiv \target{b} \pmod m \\ x &= {}? \end{aligned}
Text solution

Case 1: gcd⁡(a,m)=1\gcd(\step{a}, m) = \holds{1}: Solve 17x≡3(mod43)\step{17}x \equiv \target{3} \pmod{43}

Multiply both sides by 17−1≡−5(mod43)\step{17}^{\inverse{-1}} \equiv \inverse{-5} \pmod{43} and add a lap of 43\laps{43}Because gcd⁡(17,43)=1\gcd(\step{17}, 43) = \holds{1}, there is one unique solution on the 4343-hour clock, and multiplying by −5\inverse{-5} is much faster by hand than multiplying by 38\inverse{38} before shifting to a positive hour:
(−5)⋅17x≡(−5)⋅3(mod43)x≡−15(mod43)x≡−15+43=28(mod43)\displaystyle \begin{aligned} (\inverse{-5}) \cdot \step{17}x &\equiv (\inverse{-5}) \cdot \target{3} \pmod{43} \\ x &\equiv -15 \pmod{43} \\ x &\equiv -15 + \laps{43} \\ &= 28 \pmod{43} \end{aligned}

Case 2: gcd⁡(a,m)=g>1\gcd(\step{a}, m) = \shared{g} > 1 and g∤b\shared{g} \nmid \target{b}: Solve 4x≡3(mod10)\step{4}x \equiv \target{3} \pmod{10}

Check whether gcd⁡(4,10)\gcd(\step{4}, 10) divides the target 3\target{3}Steps of 4\step{4} on a 1010-hour clock only land on multiples of gcd⁡(4,10)=2\gcd(\step{4}, 10) = \shared{2}, so they can never hit the odd target 3\target{3}:
gcd⁡(4,10)\displaystyle \gcd(\step{4}, 10) =2∤3  ⟹  no solution\displaystyle = \shared{2} \nmid \target{3} \implies \fails{\text{no solution}}

Case 3: gcd⁡(a,m)=g>1\gcd(\step{a}, m) = \shared{g} > 1 and g∣b\shared{g} \mid \target{b}: Solve 4x≡6(mod10)\step{4}x \equiv \target{6} \pmod{10}

Divide the step size, target, and clock size by gcd⁡(4,10)=2\gcd(\step{4}, 10) = \shared{2}Because 4x=6+10k\step{4}x = \target{6} + \laps{10k} is divisible by 2\shared{2} in every term, scaling the whole equation down by 2\shared{2} gives a congruence on a 55-hour clock where the new step size and clock size share no factors:
42x≡62(mod102)2x≡3(mod5)\displaystyle \begin{aligned} \frac{\step{4}}{\shared{2}}x &\equiv \frac{\target{6}}{\shared{2}} \pmod{\frac{10}{\shared{2}}} \\ \step{2}x &\equiv \target{3} \pmod 5 \end{aligned}
Multiply both sides by 2−1≡3(mod5)\step{2}^{\inverse{-1}} \equiv \inverse{3} \pmod 5 to solve on the 55-hour clockSince 2×3=6≡1(mod5)\step{2} \times \inverse{3} = 6 \equiv \target{1} \pmod 5, multiplying by 3\inverse{3} isolates xx modulo 55:
3⋅(2x)≡3⋅3(mod5)x≡9≡4(mod5)\displaystyle \begin{aligned} \inverse{3} \cdot (\step{2}x) &\equiv \inverse{3} \cdot \target{3} \pmod 5 \\ x &\equiv 9 \equiv 4 \pmod 5 \end{aligned}
Add steps of 102=5\tfrac{10}{\shared{2}} = \laps{5} to list both solutions on the 1010-hour clockBecause 4×5=20\step{4} \times \laps{5} = \laps{20} is already two full laps of 1010, the pattern of 4x\step{4}x repeats every 5\laps{5} hours and hits 6\target{6} twice on the 1010-hour clock:
x\displaystyle x =4andx\displaystyle = 4 \quad \text{and} \quad x =4+5\displaystyle = 4 + \laps{5} =9(mod10)\displaystyle = 9 \pmod{10}
00
11
22
33
44
x=4x = 4
2x≡3(mod5)\htmlClass{lc-blue}{2}x \equiv \htmlClass{lc-pink}{3} \pmod 5
00
11
22
33
44
55
66
77
88
99
x=4x = 4
+5\htmlClass{lc-green}{+5}
x=9x = 9
4x≡6(mod10)\htmlClass{lc-blue}{4}x \equiv \htmlClass{lc-pink}{6} \pmod{10}

In 4x≡b(mod10)\step{4}x \equiv \target{b} \pmod{10}, the path of 4x\step{4}x wraps twice around the even hours of the 1010-hour clock, so odd targets b\target{b} are never hit while every even target b\target{b} is hit by two inputs xx spaced 5\laps{5} hours apart.

Taking steps of four around a ten-hour clock loops twice through the even hours, hitting every even hour at two inputs five hours apart and missing every odd hour.
5

Cancelling Common Factors in a Congruence

Scaling the clock down when we divide by a shared factor also tells us when we are allowed to cross out a common multiplier c\step{c} from both sides of c⋅a≡c⋅b(modm)\step{c} \cdot \kept{a} \equiv \step{c} \cdot \kept{b} \pmod m.

Cancelling Common Factors in a Congruence
c⋅a≡c⋅b(modm)  ⟹  ?a≡b(modm)\displaystyle \begin{aligned} \step{c} \cdot \kept{a} &\equiv \step{c} \cdot \kept{b} \pmod m \\ \overset{?}{\implies} \kept{a} &\equiv \kept{b} \pmod m \end{aligned}

When gcd⁡(c,m)=1\gcd(\step{c}, m) = \holds{1}, cancelling c\step{c} is really multiplying both sides by c−1(modm)\step{c}^{\inverse{-1}} \pmod m, so the clock size stays at mm:

3⋅2≡3⋅12(mod10)  ⟹  2≡12(mod10)(gcd⁡(3,10)=1)\displaystyle \begin{aligned} \step{3} \cdot \kept{2} &\equiv \step{3} \cdot \kept{12} \pmod{10} \\ \implies \kept{2} &\equiv \kept{12} \pmod{10} \\ &\quad \bigl(\gcd(\step{3}, 10) = \holds{1}\bigr) \end{aligned}

When gcd⁡(c,m)=g>1\gcd(\step{c}, m) = \shared{g} > 1, c\step{c} has no inverse modulo mm; dividing both sides by c\step{c} also divides the shared factor g\shared{g} out of the clock size:

2⋅3≡2⋅8(mod10)  ⟹  3≡8(mod102)  ⟹  3≡8(mod5)(gcd⁡(2,10)=2)\displaystyle \begin{aligned} \step{2} \cdot \kept{3} &\equiv \step{2} \cdot \kept{8} \pmod{10} \\ \implies \kept{3} &\equiv \kept{8} \pmod{\frac{10}{\shared{2}}} \\ \implies \kept{3} &\equiv \kept{8} \pmod 5 \\ &\quad \bigl(\gcd(\step{2}, 10) = \shared{2}\bigr) \end{aligned}

In general, for any common factor c\step{c}:

c⋅a≡c⋅b(modm)  ⟹  {a≡b(modm)if gcd⁡(c,m)=1a≡b(modmg)if gcd⁡(c,m)=g>1\displaystyle \begin{aligned} &\step{c} \cdot \kept{a} \equiv \step{c} \cdot \kept{b} \pmod m \implies \\ &\begin{cases} \kept{a} \equiv \kept{b} \pmod m & \text{if } \gcd(\step{c}, m) = \holds{1} \\[4pt] \kept{a} \equiv \kept{b} \pmod{\tfrac{m}{\shared{g}}} & \text{if } \gcd(\step{c}, m) = \shared{g} > 1 \end{cases} \end{aligned}
6

Summary

Here is how modular inverses, linear congruences, and cancellation all come down to checking the greatest common factor with the clock size.

Summary
a−1:a⋅x≡1(modm)\displaystyle \step{a}^{\inverse{-1}}: \quad \step{a} \cdot \inverse{x} \equiv \target{1} \pmod m

Key concepts

Every question about dividing or cancelling on an mm-hour clock starts by checking g=gcd⁡(a,m)\shared{g} = \gcd(\step{a}, m):

When g=1\shared{g} = \holds{1} (no shared factors with the clock)

The modular inverse a−1\step{a}^{\inverse{-1}} exists and is the unique hour x\inverse{x} satisfying ax≡1(modm)\step{a}\inverse{x} \equiv \target{1} \pmod m. On a small clock, do not run the Euclidean algorithm; just test a few multiples to spot the pair that lands 1\target{1} past a multiple of mm, like 3⋅5=15≡1(mod7)\step{3} \cdot \inverse{5} = 15 \equiv \target{1} \pmod 7 giving 3−1≡5(mod7)\step{3}^{\inverse{-1}} \equiv \inverse{5} \pmod 7. On a large clock, run the Euclidean algorithm and back-substitute to write Bézout's Identity ax+my=1\step{a}\inverse{x} + \laps{my} = \target{1}, then drop my≡0(modm)\laps{my} \equiv 0 \pmod m so the coefficient of a\step{a} is a−1\step{a}^{\inverse{-1}} (2(43)−5(17)=1\laps{2(43)} - \inverse{5}(\step{17}) = \target{1}   ⟹  17−1≡−5≡38(mod43)\implies \step{17}^{\inverse{-1}} \equiv \inverse{-5} \equiv \inverse{38} \pmod{43}). Multiplying both sides of ax≡b(modm)\step{a}x \equiv \target{b} \pmod m by a−1\step{a}^{\inverse{-1}} gives its single solution modulo mm, and cancelling a\step{a} from a⋅u≡a⋅v(modm)\step{a} \cdot \kept{u} \equiv \step{a} \cdot \kept{v} \pmod m leaves the modulus mm unchanged.

When g>1\shared{g} > 1 (shares a factor with the clock)

Do not look for a−1(modm)\step{a}^{\inverse{-1}} \pmod m, because multiples of a\step{a} only land on multiples of g\shared{g} and never reach 1\target{1}. To solve ax≡b(modm)\step{a}x \equiv \target{b} \pmod m, check whether g\shared{g} divides the target b\target{b}:

  • If g∤b\shared{g} \nmid \target{b}, stop immediately: there are 0\fails{0} solutions (4x≡3(mod10)\step{4}x \equiv \target{3} \pmod{10} has no solutions because gcd⁡(4,10)=2∤3\gcd(\step{4}, 10) = \shared{2} \nmid \target{3}).
  • If g∣b\shared{g} \mid \target{b}, divide the step size, the target, and the clock size by g\shared{g} to get agx≡bg(modmg)\frac{\step{a}}{\shared{g}}x \equiv \frac{\target{b}}{\shared{g}} \pmod{\tfrac{m}{\shared{g}}}, solve for the single answer on the smaller clock (modmg)\pmod{\tfrac{m}{\shared{g}}}, and add steps of mg\laps{\tfrac{m}{\shared{g}}} to get all g\shared{g} solutions on the original clock (4x≡6(mod10)\step{4}x \equiv \target{6} \pmod{10} →2x≡3(mod5)\to \step{2}x \equiv \target{3} \pmod 5 →x≡4(mod5)\to x \equiv 4 \pmod 5 →x=4,9(mod10)\to x = 4, 9 \pmod{10}).
  • Likewise, cancelling c\step{c} from c⋅a≡c⋅b(modm)\step{c} \cdot \kept{a} \equiv \step{c} \cdot \kept{b} \pmod m divides the modulus by g=gcd⁡(c,m)\shared{g} = \gcd(\step{c}, m) to give a≡b(modmg)\kept{a} \equiv \kept{b} \pmod{\tfrac{m}{\shared{g}}} (2⋅3≡2⋅8(mod10)\step{2} \cdot \kept{3} \equiv \step{2} \cdot \kept{8} \pmod{10}   ⟹  3≡8(mod5)\implies \kept{3} \equiv \kept{8} \pmod 5).
7

Practice

1

Which numbers in {0,1,2,…,13}\{0, 1, 2, \dots, 13\} have a modular inverse modulo 1414? Find the modular inverse of each one.

Check which numbers in {0,1,…,13}\{0, 1, \dots, 13\} avoid the prime factors of 1414, then pair them up so their product is 1\target{1} more than a multiple of 1414.

A number a\step{a} has an inverse modulo 1414 if and only if gcd⁡(a,14)=1\gcd(\step{a}, 14) = \holds{1}. Since 14=2×714 = \shared{2} \times \shared{7}, we rule out all even numbers and 77. (Watch out for the slip of keeping 77 just because it is odd: gcd⁡(7,14)=7≠1\gcd(\step{7}, 14) = \shared{7} \neq 1, so 7\step{7} has no inverse modulo 1414.) This leaves 1,3,5,9,11,\step{1}, \step{3}, \step{5}, \step{9}, \step{11}, and 13\step{13}.
To find each inverse, we look for the multiplier that gives ax≡1(mod14)\step{a}\inverse{x} \equiv \target{1} \pmod{14} (be careful not to take 14−a\fails{14 - \step{a}}, such as pairing 3\step{3} with 11\fails{11} and 5\step{5} with 9\fails{9}, which gives a+x≡0(mod14)\step{a} + x \equiv 0 \pmod{14} instead of ax≡1(mod14)\step{a}\inverse{x} \equiv \target{1} \pmod{14}):
1×1=1≡1(mod14)\step{1} \times \inverse{1} = 1 \equiv \target{1} \pmod{14}, so 1−1≡1\step{1}^{\inverse{-1}} \equiv \inverse{1}.
3×5=15=1(14)+1≡1(mod14)\step{3} \times \inverse{5} = 15 = \laps{1(14)} + \target{1} \equiv \target{1} \pmod{14}, so 3−1≡5\step{3}^{\inverse{-1}} \equiv \inverse{5} and 5−1≡3\step{5}^{\inverse{-1}} \equiv \inverse{3}.
9×11=99=7(14)+1≡1(mod14)\step{9} \times \inverse{11} = 99 = \laps{7(14)} + \target{1} \equiv \target{1} \pmod{14}, so 9−1≡11\step{9}^{\inverse{-1}} \equiv \inverse{11} and 11−1≡9\step{11}^{\inverse{-1}} \equiv \inverse{9}.
13×13=169=12(14)+1≡1(mod14)\step{13} \times \inverse{13} = 169 = \laps{12(14)} + \target{1} \equiv \target{1} \pmod{14}, so 13−1≡13\step{13}^{\inverse{-1}} \equiv \inverse{13}.
The numbers with inverses modulo 1414 are 1,3,5,9,11,13\step{1}, \step{3}, \step{5}, \step{9}, \step{11}, \step{13}, with 1−1≡1\step{1}^{\inverse{-1}} \equiv \inverse{1}, 3−1≡5\step{3}^{\inverse{-1}} \equiv \inverse{5}, 5−1≡3\step{5}^{\inverse{-1}} \equiv \inverse{3}, 9−1≡11\step{9}^{\inverse{-1}} \equiv \inverse{11}, 11−1≡9\step{11}^{\inverse{-1}} \equiv \inverse{9}, and 13−1≡13\step{13}^{\inverse{-1}} \equiv \inverse{13}.
2

Use the Euclidean algorithm and Bézout's Identity to find the modular inverse of 19\step{19} modulo 5151, and use it to solve 19x≡5(mod51)\step{19}x \equiv \target{5} \pmod{51} for xx in {0,1,…,50}\{0, 1, \dots, 50\}.

Run the Euclidean algorithm on 5151 and 19\step{19} down to a remainder of 1\target{1}, back-substitute to write 1\target{1} as a combination of 5151 and 19\step{19}, and reduce modulo 5151.

Running the Euclidean algorithm on 5151 and 19\step{19} gives:
51=2(19)+13  ⟹  13=51−2(19)19=1(13)+6  ⟹  6=19−1(13)13=2(6)+1  ⟹  1=13−2(6)\displaystyle \begin{aligned} 51 &= 2(\step{19}) + \leftover{13} \\ \implies \leftover{13} &= 51 - 2(\step{19}) \\[4pt] \step{19} &= 1(\leftover{13}) + \leftover{6} \\ \implies \leftover{6} &= \step{19} - 1(\leftover{13}) \\[4pt] \leftover{13} &= 2(\leftover{6}) + \target{1} \\ \implies \target{1} &= \leftover{13} - 2(\leftover{6}) \end{aligned}
Back-substituting through the remainders gives:
1=13−2(6)=13−2[19−1(13)]=3(13)−2(19)=3[51−2(19)]−2(19)=3(51)−8(19)\displaystyle \begin{aligned} \target{1} &= \leftover{13} - 2(\leftover{6}) \\ &= \leftover{13} - 2\bigl[\step{19} - 1(\leftover{13})\bigr] \\ &= 3(\leftover{13}) - 2(\step{19}) \\ &= 3\bigl[51 - 2(\step{19})\bigr] - 2(\step{19}) \\ &= 3(51) - 8(\step{19}) \end{aligned}
Reducing modulo 5151 drops 3(51)≡0(mod51)\laps{3(51)} \equiv 0 \pmod{51} and leaves 1≡−8⋅19(mod51)\target{1} \equiv \inverse{-8} \cdot \step{19} \pmod{51}. (Do not drop the minus sign on −8(19)\inverse{-8}(\step{19}) and take 19−1≡8\step{19}^{\inverse{-1}} \equiv \fails{8}, which would give x≡8⋅5=40(mod51)x \equiv \fails{8} \cdot \target{5} = \fails{40} \pmod{51}.) Converting −8\inverse{-8} to a positive clock number gives 19−1≡−8≡43(mod51)\step{19}^{\inverse{-1}} \equiv \inverse{-8} \equiv \inverse{43} \pmod{51}.
Multiplying 19x≡5(mod51)\step{19}x \equiv \target{5} \pmod{51} by −8\inverse{-8} gives:
x≡(−8)⋅5\displaystyle x \equiv (\inverse{-8}) \cdot \target{5} =−40≡−40+51\displaystyle = -40 \equiv -40 + \laps{51} =11(mod51)\displaystyle = 11 \pmod{51}
So 19−1≡43(mod51)\step{19}^{\inverse{-1}} \equiv \inverse{43} \pmod{51} and x=11x = 11.
3

Does the linear congruence 15x≡22(mod35)\step{15}x \equiv \target{22} \pmod{35} have any solutions? Explain how you can tell without testing values of xx.

Find gcd⁡(15,35)\gcd(\step{15}, 35) to see which hours a step size of 15\step{15} can visit on a 3535-hour clock, then check whether the target 22\target{22} is one of them.

Check the greatest common factor of the step size 15\step{15} and the clock size 3535: gcd⁡(15,35)=5\gcd(\step{15}, 35) = \shared{5}. (Be careful not to check gcd⁡(15,22)=1\gcd(\step{15}, \target{22}) = 1 between the step size and the target, which would falsely suggest a solution exists.) Because gcd⁡(15,35)=5\gcd(\step{15}, 35) = \shared{5}, steps of size 15\step{15} on a 3535-hour clock only ever land on multiples of 5\shared{5}. Since 22\target{22} is not divisible by 5\shared{5}, there are 0\fails{0} solutions.
4

Find all solutions to 9x≡12(mod21)\step{9}x \equiv \target{12} \pmod{21} on a 2121-hour clock (xx in {0,1,…,20}\{0, 1, \dots, 20\}).

Divide the step size, target, and clock size by gcd⁡(9,21)\gcd(\step{9}, 21) first; after solving on the smaller clock, how many hours apart are the solutions on the 2121-hour clock?

Since gcd⁡(9,21)=3\gcd(\step{9}, 21) = \shared{3} and 3\shared{3} divides 12\target{12}, there are 3\shared{3} solutions modulo 2121. Dividing the step size, target, and clock size by 3\shared{3} gives:
3x≡4(mod7)\displaystyle \step{3}x \equiv \target{4} \pmod 7
(Watch out for the slip of dividing 9\step{9} and 12\target{12} by 3\shared{3} while leaving the modulus at 21\fails{21}, which gives the unsolvable congruence 3x≡4(mod21)\step{3}x \equiv \target{4} \pmod{\fails{21}}.)
On a 77-hour clock, 3×5=15≡1(mod7)\step{3} \times \inverse{5} = 15 \equiv \target{1} \pmod 7, so 3−1≡5(mod7)\step{3}^{\inverse{-1}} \equiv \inverse{5} \pmod 7. Multiplying both sides by 5\inverse{5} gives:
x≡5⋅4\displaystyle x \equiv \inverse{5} \cdot \target{4} =20≡6(mod7)\displaystyle = 20 \equiv 6 \pmod 7
To get all three solutions on the 2121-hour clock from x≡6(mod7)x \equiv 6 \pmod 7, we add steps of 213=7\tfrac{21}{\shared{3}} = \laps{7} (do not stop at the single answer x=6x = 6, and do not add steps of gcd⁡(9,21)=3\gcd(\step{9}, 21) = \shared{3}, which would give 6,9,126, \fails{9}, \fails{12}):
x\displaystyle x =6,6+7\displaystyle = 6, \quad 6 + \laps{7} =13,13+7\displaystyle = 13, \quad 13 + \laps{7} =20\displaystyle = 20
5

Suppose a\kept{a} and b\kept{b} are integers. (a) If 7a≡7b(mod18)\step{7}\kept{a} \equiv \step{7}\kept{b} \pmod{18}, what congruence between a\kept{a} and b\kept{b} follows? (b) If 12a≡12b(mod18)\step{12}\kept{a} \equiv \step{12}\kept{b} \pmod{18}, what congruence between a\kept{a} and b\kept{b} follows? Give an example of two integers a\kept{a} and b\kept{b} that satisfy 12a≡12b(mod18)\step{12}\kept{a} \equiv \step{12}\kept{b} \pmod{18} with a≢b(mod18)\kept{a} \not\equiv \kept{b} \pmod{18}.

Check gcd⁡(c,18)\gcd(\step{c}, 18) for the multiplier c\step{c} being cancelled in each part to see whether the modulus 1818 stays the same or gets divided by gcd⁡(c,18)\gcd(\step{c}, 18), then pick two numbers in part (b) that differ by the new modulus.

(a) Since gcd⁡(7,18)=1\gcd(\step{7}, 18) = \holds{1}, cancelling 7\step{7} keeps the modulus unchanged: a≡b(mod18)\kept{a} \equiv \kept{b} \pmod{18}.
(b) Since gcd⁡(12,18)=6\gcd(\step{12}, 18) = \shared{6}, cancelling 12\step{12} divides the modulus 1818 by 6\shared{6} (do not leave the modulus as 1818, and notice that we divide 1818 by gcd⁡(12,18)=6\gcd(\step{12}, 18) = \shared{6}, not by 12\step{12}):
a≡b(mod186)  ⟹  a≡b(mod3)\displaystyle \kept{a} \equiv \kept{b} \pmod{\frac{18}{\shared{6}}} \implies \kept{a} \equiv \kept{b} \pmod 3
Picking two integers that are 3\laps{3} apart, such as a=1\kept{a} = 1 and b=4\kept{b} = 4, gives 12(1)=12\step{12}(1) = 12 and 12(4)=48≡12(mod18)\step{12}(4) = 48 \equiv 12 \pmod{18}, so 12a≡12b(mod18)\step{12}\kept{a} \equiv \step{12}\kept{b} \pmod{18} with 1≢4(mod18)1 \not\equiv 4 \pmod{18}.
6

Prove that if gcd⁡(a,m)=1\gcd(\step{a}, m) = \holds{1}, then the modular inverse of a\step{a} modulo mm is unique on an mm-hour clock: if ax≡1(modm)\step{a}\inverse{x} \equiv \target{1} \pmod m and ay≡1(modm)\step{a}\inverse{y} \equiv \target{1} \pmod m, explain why x≡y(modm)\inverse{x} \equiv \inverse{y} \pmod m.

Set the two left-hand sides congruent to each other modulo mm, then use what gcd⁡(a,m)=1\gcd(\step{a}, m) = \holds{1} tells you about cancelling a\step{a}.

Suppose ax≡1(modm)\step{a}\inverse{x} \equiv \target{1} \pmod m and ay≡1(modm)\step{a}\inverse{y} \equiv \target{1} \pmod m. Then both ax\step{a}\inverse{x} and ay\step{a}\inverse{y} land on 1\target{1} on the mm-hour clock, so:
ax≡ay(modm)\displaystyle \step{a}\inverse{x} \equiv \step{a}\inverse{y} \pmod m
(Be careful not to write ax=ay\step{a}\inverse{x} = \step{a}\inverse{y} as ordinary integers: ax\step{a}\inverse{x} and ay\step{a}\inverse{y} only agree modulo mm, and cancelling a\step{a} without changing the modulus requires using gcd⁡(a,m)=1\gcd(\step{a}, m) = \holds{1}.) Because gcd⁡(a,m)=1\gcd(\step{a}, m) = \holds{1}, cancelling the common factor a\step{a} from both sides keeps the clock size mm unchanged (equivalently, multiplying both sides by an inverse of a\step{a} modulo mm turns a\step{a} into 1\target{1}), which gives x≡y(modm)\inverse{x} \equiv \inverse{y} \pmod m. Therefore, the inverse of a\step{a} is unique modulo mm.