How to find the value of $x$ that satisfies $3x=4$ in $\mathbb Z/5\mathbb Z$? Let $\mathbb Z_5 = \mathbb Z/5\mathbb Z$.
The value of $x$ which satisfies the equation $3x = 4\bmod 5$ is...?
The answer is $3$. I understand why the answer is $3$, but not how it was derived. Is there an equation or process I can use that will give me the correct answer no matter how large the numbers in the equation?

Consider equations of the form $m\cdot x = n\bmod p$, where $p$ is a prime number.
The other answer is a correct way to derive the solution, but it takes as many as $p$ tries to find it in the worst case. A more efficient solution is the following. First, compute $m^{-1}$, that is, the only solution $y$ to the equation $m\cdot y = 1\bmod p$. This can be done using the extended euclidean algorithm. Then, let $x:= m^{-1}\cdot n$. One can then check that $m\cdot x = mm^{-1}n \bmod p = n\bmod p$.
In case $p$ is not a prime number, one can also use this method in the case that $m$ and $p$ are coprime (which guarantees the existence of $m^{-1}$). Suppose now that $p$ and $m$ share a factor, and call it $q$. If $n$ is not divisible by $q$, then there is no solution (you can prove this using arithmetic modulo $q$). If $q$ also divides $n$, then the equation reduces to $\frac{m}{q}\cdot x = \frac{n}{q}\bmod \frac{p}{q}$. You can now continue this process, until you find a solution.
