# How to solve this congruence $17x \equiv 1 \pmod{23}$?

Given $17x \equiv 1 \pmod{23}$

How to solve this linear congruence? All hints are welcome.

edit: I know the Euclidean Algorithm and know how to solve the equation $17m+23n=1$ but I don't know how to compute x with the use of m or n.

To do modular division I do this:

an - bm = c where c is dividend, b is modulo and a is divisor, then n is quotient

17n - 23m = 1

Then using euclidean algorithm, reduce to gcd(a,b) and record each calculation

As described by http://mathworld.wolfram.com/DiophantineEquation.html

17 23 $\quad$ 14 19

17 6 $\quad\;\;$ 14 5

11 6 $\quad\;\;\;\;$ 9 5

5 6 $\quad\;\;\;\;\;$ 4 5

5 1 $\quad\;\;\;\;\;$ 4 1

1 1 $\quad\;\;\;\;\;$ 0 1

Left column is euclidean algorithm, Right column is reverse procedure

Therefore $17*19 - 23*14 = 1$, i.e. n=19 and m=14.

The result is that 1/17 ≡ 19 mod 23

this method might not be as quick as the other posts, but this is what I have implemented in code. The others could also be, but I thought I would share my method.

Algorithmically one can employ the Extended Euclidean Algorithm to invert $\,17\,$ modulo $\,23\,$ (possible since they are coprime). But for small numbers it is usually quicker to use other methods, e.g. rewriting $\,17^{-1} \equiv \frac{1}{17}$ as a fraction, then adding $\pm$modulus to the numerator and denominator until one obtains an exact quotient. Do this $\rm\color{#0a0}{first}$ to minimize the absolute value of the denominator (to increase the probability of an exact quotient), and $\rm\color{#c00}{then}$ do the same to the numerator, aiming to obtain a multiple of the denominator. For example

$${\rm mod}\ 23\!:\,\ 17x\equiv 1\,\Rightarrow\,x \,\equiv\, \dfrac{1}{\color{#0a0}{17}} \,\equiv\, \dfrac{\color{#c00}1}{\color{#0a0}{-6}}\,\color{#c00}\equiv\,\dfrac{\color{#c00}{24}}{-6} \,\equiv\, -4 \,\equiv\, 19\qquad\qquad$$

We subtracted $23$ from the denominator to get the minimal integer $\,\color{#0a0}{-6 \equiv 17}\pmod {23},\,$ then since $\,23\equiv -\color{#c00}{1}\pmod 6,\,$ we add it the numerator $(= \color{#c00}1)$ to make it be divisible by $6$.

Beware $\$ For non-prime moduli one must be sure to restrict to denominators that are coprime to the modulus (so invertible), so to avoid the modular analog of dividing by zero.

In this example the described method ends up being essentially a special case of said algorithm, reinterpreted in fractional form. But that is not always so. The advantage of the fractional form is that it allows one to use well-known fractional arithmetic (subject to said restriction), e.g. cancelling common factors. One can find many worked examples is my prior posts.

By Fermat's little theorem, $a^{p-1} \equiv 1$ (mod p) for prime number p. So $x=17^{21}$ should work for sure. There can be smaller numbers satisfying this.

• Way overkill... – vonbrand Jun 22 '14 at 2:37

Hint: If you do not want to find result by trying numbers,

By Euclidean algorithm , you can find $m,n$ such that $$17m+23n=1$$ $$17m\equiv1 \ mod \ 23$$ so $m$ is the inverse of $17$ then result follows.

$$17x\equiv1\pmod{23}\\-6x\equiv-22\pmod{23}\\3x\equiv11\pmod{23}\\-20x\equiv-12\pmod{23}\\5x\equiv-20\pmod{23}\\x\equiv-4\pmod{23}\\x\equiv19\pmod{23}$$

• Basically, you've been executing the Euclidean algorithm. – punctured dusk Jun 21 '14 at 15:06
• @barto Maybe,I don't really know what Euclidean algorithm is(seemed to long and not interasting),I just used the mod properties and division – kingW3 Jun 21 '14 at 20:05
• It is indeed long and not that interesting. As you experienced, it's perfectly possible to live without it. It's an algorithm to write the $\gcd$ of two integers as a linear combination of those integers, and can be used to calculate the inverse in congruences when the $\gcd$ is $1$. Here: $\gcd(17,23)=1=19\cdot17+\ldots\cdot23$, so the inverse of $17$ is $19$. – punctured dusk Jun 21 '14 at 20:31

Hint: $4 \cdot 17 \equiv -1$ mod $23$

And thus $4 \cdot 17x \equiv 4 (\text{mod} 23) \Leftrightarrow -x \equiv 4 (\text{mod} 23) \Leftrightarrow x \equiv -4 (\text{mod} 23)\Leftrightarrow x \equiv 19 (\text{mod} 23)$.

• That… that is probably the most obliquely useful hint I can imagine. – Eric Stucky Jun 21 '14 at 10:16
• Yes and I cannot understand why the others gave something much more difficult... will edit my answer with a spoiler – Nicky Hekster Jun 21 '14 at 12:49
• @NickyHekster: I do not think Euclidean algorithm is diffucult. – mesel Jun 21 '14 at 13:17
• Agree, but the OP does not give any context and nor exhibits his level of knowledge, so ... – Nicky Hekster Jun 21 '14 at 13:18
• The answer appears to be pulled out of a hat. That's great for magic, but not for math. To remedy that you should say how you discovered that $\ 4\cdot 17\equiv -1.$ – Bill Dubuque Jun 21 '14 at 14:44

A sort of naive way I came up with once when I was being lazy in class:

\begin{align} \ 17x - 1 &= 23n \\ \ 17x - 23n &= 1 \\ \ 17x - 17n - 6n &= 1 \\ \ 17(x - n) &= 1 + 6n \\ \end{align}

From here, we need to find $n$ such that $6n$ is $1$ less than a multiple of $17$. So look through multiples of $17$: $17, 34, 51, 68, 85$ — there it is, $85$. Let $n = 14$; this means $x - n = 5$ and so $x = 19$. (Which, of course, is not the only answer.)

• This is equivalent to doing the first couple steps of the extended euclidean algorithm (same as I do in fractional form in my answer). – Bill Dubuque Jun 21 '14 at 16:59

No hints, just a solution.

[For the following paragraphs, please refer to the figure at the end of the last paragraph (the figure is also available in PDF).]

The manipulations performed from steps (0) to (17) were designed to create the linear system of equations (2a), (7a), (12a) and (17a). The manipulations end when the absolute value of a coefficient of the latest equation added is 1 (see (17a)).

It is possible to infer equations (7a), (12a) and (17a) from (0), (7) and (12) respectively without performing manipulations (0) to (17) directly. In every case, select the smallest absolute value coefficient, generate the next equation by replacing every coefficient with the remainder of the coefficient divided by the selected coefficient (smallest absolute value coefficient) – do the same with the right-hand constant – and add the new variable whose coefficient is the smallest absolute value coefficient. If the new equation has a greatest common divisor greater than one, divide the equation by the greatest common divisor. Stop when the absolute value of a coefficient of the latest equation added is 1.

simplest answer is x=1/17 because 17x=1mod 23 17

17x=1mod23, 23 divede (17x-1) if x=1/17, 17*1/17=1, 1=1mod23, since 23 divide (1-1), 23 divide 0

• needs to be integer answer – Sam Jul 4 '14 at 0:26
• another answer for x is -4.Because (17x-1)/23.If x=-4,(17*-4-1)=-69,-69/23=-3 – user159480 Jul 5 '14 at 9:27