<s>[INST] Modular arithmetic $(2n+1)x \equiv -7 \pmod 9$ Find a solution $(2n+1)x \equiv -7 \pmod 9$
I’m sure this is trivial but I still have doubts about it.
I know the equation has solution for certain $n \in \mathbb {Z}$. Actually I have tried a few and got a similar results (with Diophantine equations ). I wonder if there’s general solution for the equation without changing the n for an integer.
Thanks in advance.
 [/INST] $9$ is not prime so it has $0$ divisors and you cant solve $3x \equiv k\pmod 9$ unless $k$ is a multiple of $3$.
Basically if $\gcd(m, n) = 1$ there will always be a solution (and only one solution) to $mx \equiv 1\pmod n$.  We can notate that solution as $m^{-1}$. ( So for example $5^{-1} = 2\pmod 9$ because $2*5 \equiv 1 \pmod 9$.
So for any $mx \equiv k \pmod n$ we can do $m^{-1}mx \equiv m^{-1}k\pmod n$ and so $x \equiv m^{-1}k\pmod n$.  So in your example if $2n +1 = 5$ we could solve $5x\equiv -7\pmod 9$ so $2*5x \equiv x \equiv 2*(-7)\equiv -14\equiv -5 \equiv 4\pmod 9$.  (And indeed $4*5 \equiv -7\pmod 9$).
But if $\gcd(m,n) \ne 1$ this does not follow unless $k$ is a multiple of $\gcd(m,n)$.   But if $k$ is a multiple of $\gcd(m,n)$ we can solve. 
.....
To put this all in perspective these are actually just a restatement of Bezouts lemma.
$mx \equiv k \pmod n$ is solveable if and only if there if is an integer $w$ so that $mx + wn = k$ which is solveable if and only if $k$ is a multiple of $\gcd(m,n)$.
So to solve $(2n + 1)x \equiv -7\pmod 9$: as $-7$ is not a multiple of an factor of $9$ other than $1$, this will only be solvable if $\gcd(2n+1, 9)= 1$.
So we may if and only if $2n+1$ is not a multiple of $3$.  Or in other words if and only if $2n+1 \not \equiv 0\pmod 3$ or $2n\not \equiv -1\pmod 3$ or $n \not \equiv 1\pmod 3$.
..... so final answer .....
For there to be solutions we can't have $n\equiv 1\pmod 3$. In other words we cant have $n\equiv 1,4,7\pmod 9$.
So we can have solutions if $n \equiv 0,2,3,5,6,8 \pmod 9$.
In those case $2n+1 \equiv 1,2,4,5,7,8\pmod 9$.
We can find $(2n+1)^{-1}\mod 9$ for those values.
$1*1 = 1; 2*5\equiv 1; 4*7\equiv 1; 5*2\equiv 1; 7*4\equiv 1; 8*\equiv 1\pmod 9$ so $(2n+1)^{-1}\equiv 1,5,7,2,4,8\pmod 9$ when $n \equiv 0,2,3,5,6,8\pmod 9$ respectively.
So solution to $(2n+1)x \equiv -7 \equiv 2 \pmod 9$ is $x\equiv (2n+1)^{-1}*2 \pmod 9$.
So if $n \equiv 0,2,3,5,6,8\pmod 9$ then $x \equiv (2n+1)^{-1}*2 \equiv 1*2,5*2,7*2,2*2,4*2, 8*2 \equiv 2,1,5,4,8,7\pmod 9$ respectively.
</s>