How do I simplify a modular congruence? If I have $$13x\equiv 15 \pmod{35}$$ or something like $$197x\equiv -1 \pmod{371}$$
How do I go about making the coefficient of the $13x$ and $197x$ $1$? Brute forcing this would take far too long. I know that you can use the Extended Euclidean Algorithm and Modular Inverses to solve, but I am unsure how.
 A: You have that $\operatorname{gcd}(35,13)=1$. This enables us to find a linear combination
$35a+13b=1$ where $a,b\in\mathbb{Z}$. This is known as Bézout's Identity.
This is done as follows.
With the euclidean algorithm you can caculate the greatest common divisor, in this case $1$, like this:
$$35=2\cdot 13+9$$
$$13=1\cdot 9+4$$
$$9=2\cdot 4+1$$
$$4=1\cdot 4+0$$
Now to get the linear combination, we reverse this process, by substituting in the expression.
We want to get a linear combination in terms of $35$ and $13$ that equals $1$.
We start with the equality $9=2\cdot 4+1\Leftrightarrow 1=9-2\cdot 4$.
Now we solve the equation in the preceeding line (in the algorithm) for $4$ and substitute that in.
We have $4=13- 9$, hence
$1=9-2(13-9)=3\cdot 9-2\cdot 13$.
Now we do the same for $9$. This gives us:
$1=3(35-2\cdot 13)-2\cdot 13=3\cdot 35-8\cdot 13$, and we have found the linear combination.
So now we have
$3\cdot 35-8\cdot 13=1\Leftrightarrow 8\cdot 13=3\cdot 35-1$
Which is equivalent to $8\cdot 13\equiv -1\mod 35$.
Now multiply this by $-15$ (or $20\mod 35$).
This gives
$160\cdot 13\equiv 15\mod 35$.
So $x=160\equiv 20\mod 35$ solves the equation $13x\equiv 15\mod 35$.
The other equation can be solved similar, and is left as an exercise.
You will be able to solve this, when you go carefully line through line by the scetched method above.
Note that in the other example we also have that $\operatorname{gcd}(197,371)=1$.
That the gcd is here 1 makes it simpler to manipulate the equation (by multiplying at the end) to get the desired inverse. As we are not working in a field here (35 and 371 are not prime) you will not always find an inverse using this method, or at all.
A: Assuming you don't know how to use modular inverses (which is the way to do this and you should learn it) you can do it just be setting up equations
$13x \equiv 15 \pmod {35}$ means there exists an integer $m$ so that $13x =15 + 35m$ so $x = \frac{15 + 35m}{13}= 1 + 2m +\frac {2+9m}{13}$.
This means that $13|2+9m$ so $2+9m\equiv 0\pmod {13}$ and so $9m\equiv -2 \equiv 11\pmod {13}$.
That means there is an integer $n$ so that $9m = 11 + 13n$ and $m=\frac {11+13n}9=(n+1) + \frac {2+4n}9$.
That means $4n \equiv -2\equiv 7\pmod 9$.  Let $4n = 7 +9p$ so $n = \frac {7+9p}4 =(2p+1) + \frac{3+p}4$.
That means $p\equiv -3 \equiv 1\pmod 4$.
Let $p = 4z + 1$.
So $n = (2p+1) + \frac{3+p}4 = (2(4z+1)+1) + \frac {4z + 4}4 = 8z+3 + z + 1 =9z + 4$.
So $m =(n+1) + \frac {2+4n}9 = (9z+5) + \frac {2+4(9z+4)}9=(9z+5)+\frac{18+4\cdot 9z}9=(9z+5) + 2+4z = 13z +7$
So $x = 1 + 2m +\frac {2+9m}{13}= 1+2(13z +7) + \frac {2+9(13z+7)}{13}=(26z+15)+\frac {65 + 9\times 13z}{13}=(26z+15)+(5+9z)=20+35z$.
So $x \equiv 20 \pmod {35}$.
