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.
If $a + dn \equiv 0(\mod{b})$, $$dn \equiv -a (\mod{b}) \implies dn \equiv b - a (\mod{b})$$ (assuming $b > a$, and of course the remainder should be less than the divisor as per Euclid's Division Lemma, and remainders should be positive) $$\implies n \equiv \dfrac{b - a}d (\mod{b}) \space \text{if} \space gcd(b,d) = 1 \space \text{and} \space d \mid (b - a)$$
Therefore, $n = bx + \dfrac{b - a}d$ is the kind of $n$ you might want.
But there may arise cases where this alone won't work, so I'd suggest attending a course on some advanced topics in modular arithmetic (even I am not an expert and I used what I knew to answer this question).
Refer the suggestions in @J.W.Tanner's comments beneath your question for more methods.