For the equation $(am) \mod n = r$ for integers $a, n, r$, how can we find $m$ efficiently, if such an $m$ exists?
One very basic way I thought of was to simply enumerate all the valid $m$ from $0, \ldots, n-1$ and check them. But this can be quite slow if $n$ is large. Is there a number-theoretic way to speed this up?