An elegant result
Let $A, M$ be two positive integers such that $A < M$.
Define the sequence $\{c_n\}$ satisfies $0 \le c_n < M$ and $c_n \equiv A n (\mathrm{mod}\ M)$ for $n \ge 1$.
Moreover let $n_1 = 1$ and if $c_{n_k} > 0$, we define
Hence $A n_{k+1}$ is the first positive multiple of $A$ that yields a residual less than $c_{n_k}$.
Following theorem shows the recurrence relation of the sequence $\{n_k\}$.
Theorem 1
Suppose that $c_{n_{k+1}} > 0$, then we have
Following proof is based on the proof of brob26.