Let $m>1$ be a prime number, and $k$ and $B$ be arbitrary elements of $\{0,1,\ldots , m-1\}$. Let $A\in \{0,1,\ldots , m-1\}$ such that $\gcd(A,m)=1$. For the following definition we use $\mod{m}$ to denote an operation and not an equivalence class. We define a sequence in the following way,
$$x_0=k$$ $$x_{n+1} = (Ax_n+B)\mod{m}.$$
What is the minimum value of $n>0$ such that $x_n=k$? In the case when $A=1$, it is clear that $n=\frac{m}{\gcd(m,B)}$ is the minimum $n$ such that $x_n = k$. This is because $\frac{mB}{\gcd(m,B)}$ is the LCM of $m$ and $B$. But I don't know how to take care of the case when $A>1$, any ideas?