Question regarding determination of whether a linear congruence has solutions or not.

A linear congruence can be represented as follows:

$$ax\equiv b(\hspace{-4mm}\mod n)$$

Can we say that we can determine whether a linear congruence has solutions or not by finding the gcd of $(b+n,a)$ and the gcd$(b+n,a)$ should not equal to 1 for it having solutions?

i.e gcd$(b+n,a)=1$ then no solutions, gcd$(b+n,a) >1$ then $ax\equiv b (\hspace{-2mm}\mod n)$ has solutions

My question being can we use this method instead of the conventional method of finding the gcd of (a,n) and seeing weather it divides b or not.

Can you give a counter example to my method,


I think it is more standard to consider whether $\gcd(a,n)=1$ then $a^{-1}$ exists.

Else if $d=\gcd(a,b,n)\neq 1$ you can reduce to $\frac ad x\equiv\frac bd\pmod{\frac nd}$ and examine again first condition.

A trivial counter example to your method is obviously $a=1$ since $x\equiv b\pmod{n}$ is already solved.

But let consider two cases $\quad\begin{array}{l}3x\equiv 3 \pmod 5\\3x\equiv 4\pmod 5\end{array}$

Since $\gcd(3,5)=1$ then $3$ has an inverse and both equations are solvable by multiplication by $2$.

Yet $\quad\begin{array}{l}\gcd(b+n,a)=\gcd(8,3)=1&\text{in first case}\\\gcd(b+n,a)=\gcd(9,3)=3&\text{in second case}\end{array}\quad$ so something is off.