So basicially, given the equation $t\equiv nr\pmod{q}$ where $t,r\in\mathbb{N_0}$ and $n, q\in\mathbb{N}$ find $n$ if the rest of the variables are defined.
I've figured out a way to see if there is a solution. It appears that if the largest common divisor of $r$ and $q$ divides $t$, the solution exists. I'm not sure if this covers all the cases and I don't know how to prove it's true.
The question is, how do I find out how many times I need to add $r$ to get $t\pmod{q}$?
Edit: Obviously, if one such $n$ exists, then there are infinite $n$s for which it works. I need the smallest one.