I have an arithmetic sequence, $a+dn$, where $a$ and $d$ are constants and $n$ is the term number. How would I efficiently calculate solutions to the following equation,
$$ (a+dn)\%b=0 $$
where $b$ is also a constant. (and $\%$ means modulo)
I attempted the question myself and found out that I really just need to find the smallest $n$ that satisfies the equation and find the rest by adding ${kb\over GCD(d,b)}$ to $n$, where $k$ is any integer. I also noticed that the smallest solution will always be less than $b$ and if no solution exist within this range, then there is no solution. So I tried to find the solution by brute forcing from 0 to $b$, until I got a solution. But this method is not nearly as efficient as I need it to be.