Proof of the 2 pointer method for finding a linked list loop

If there is a loop (of $n$ nodes), then once a pointer has entered the loop it will remain there forever; so we can move forward in time until both pointers are in the loop. From here on the pointers can be represented by integers modulo $n$ with initial values $a$ and $b$. The condition for them to meet after $t$ steps is then

$a + t \equiv b + 2t \text{ mod }n$

which has solution $t = a - b \text{ mod }n$.

This will work so long as the difference between the speeds shares no prime factors with $n$.


HINT: The distance between pointers is increased by $1$ each step. The single restriction on speeds is that their diference should be coprime with the loop's length.