What is the general solution to 12x = 9 (mod n)? I know how to solve specific cases but can't find a way to express the solutions for a general n.
 A: Divide into cases. If $n$ is even, there is no solution, so from now on assume that $n$ is odd. 
There are two possibilities, (i)  $n$ is divisible by $3$ and (ii) $n$ not divisible by $3$. They are handled similarly but not identically. We do (i), and leave (ii) to you.
Let $n=3m$. Then our congruence is equivalent to $4x\equiv 3\pmod{m}$. If $m\equiv 1\pmod{4}$, then $x\equiv \frac{m+3}{4}\pmod{m}$ is the solution. If $m\equiv 3\pmod{4}$, then $x\equiv \frac{3m+3}{4}\pmod{m}$ is the solution.
A: $12x\equiv 9\pmod{n}$ has a solution if and only if $\gcd(12,n)\mid 9$ (it follows from Bézout's lemma), i.e. if and only if $n$ is odd.
So you're solving $12x+(2k+1)t=9$ in $x,t\in\Bbb Z$ given $k\in\Bbb Z^+$.
Use Extended Euclidean Algorithm (EEA) to find $a,b\in\Bbb Z$ such that $12a+(2k+1)b=\gcd(12,2k+1)$, then multiply both sides by $\frac{9}{\gcd(12,2k+1)}$.
Here's an example of how you could use EEA: let $k=2$. Subtract consecutive equations:
$$\begin{array}\\12=12(1)+5(0)\\5=12(0)+5(1)\\2=12(1)+5(-2)\\1=12(-2)+5(5)\end{array}$$
Multiply both sides by $9$ to get $9=12(-18)+5(45)$. Then $x=-18, t=45$. So the solution to $12x\equiv 9\pmod{5}$ is $x\equiv -18\equiv 2\pmod{5}$.
