Suppose $a$ and $b$ are relatively prime integers $\geq 2$. I need to find the smallest positive integer $n$ such that $b^n-1$ is divisible by $a$. Is there an efficient algorithm for finding this, or do I need to use brute force?
I looked into this a bit and the answer seems related to Euler's totient function, but the only thing I've found so far is that if $m$ (the answer I'm looking for) is the smallest such $n$, then $m \leq \phi(a)$; I didn't find anything that would tell me how I could tell when $m = \phi(a)$ or if there were any other way to narrow down the possibilities so that I wouldn't have to check every number from $1$ to $\phi(a)$.