congruence equations and inverse I got two questions that I'm wondering, one main question and one "bonus" question I guess

*

*what is the general method to solve congruence equations like $ax \equiv b \pmod m$?

Take for example $3x\equiv 2 \pmod 5$ how would I go about solving this?
I was able to solve it using trial and error and found the answer to be $4$, but I'm looking for a better and faster way to solve problems like these for larger $m$'s..
Also I'm wondering sometimes you can solve these with just the inverse of $a$, but when does that apply? only when $b=1$ and $a$ and $m$ are coprime? example $9x\equiv 1 \pmod 14$ for instance?


*can someone please show me how I can find the modular inverse of $9$  mod $14$? I'm familiar with the method used and I'm able to find the inverse in other examples, but I'm not sure why this one is causing me so much trouble, answer should be $11$ I think.


For 1): if $a$ and $m$ are coprime, the extended Euclidean algorithm gives you an automatic way  to find the coeffcicients of a Bézout's relation:
$$ua+vm=1,\quad \lvert u\rvert<m,\enspace\lvert v\rvert< a$$
This Bézout's relation tells you $u$ is a modular inverse of $a$, hence
$$ax\equiv b\mod m\iff uax\equiv ub\mod m\iff x\equiv ub\mod m. $$
If $a$ and $m$ are not coprime, let $d=\gcd(a,m)$ and write $\;a=da'$, $m=dm'$ ($\gcd(a',m')=1$). The equation writes as
$$da'x\equiv b\mod dm',$$
and it has no solution if $b\not\equiv 0\mod d$. If $b=db'$, it is equivalent to 
$$a'x\equiv b'\mod m',$$
and we're back to the first case.
For 2), a Bézout's relation between $9$ and $14$ is $2\cdot 14-3\cdot 9=1$, hence
$$9^{-1}\equiv -3\equiv 11\mod 14. $$
