# Finding integer solutions in diophantine equations

$$m, n$$ are integers, find all integer solutions of the diphantine equation:

$$nx + (n + 2)y = m$$

where $$n$$ is odd.

I´ve tried with Euclides but i get this:

$$2m = (n + 2)m - nm$$

I need a hint or something.

• Your equation is linear, so you may try and write it in the form $y = \cdots$ and see if that helps. – Ruben Jun 20 '19 at 17:41

The diophantine equation $$ax+by=c$$ has solutions if and only if $$gcd(a,b)|c$$.
So for this equation $$nx + (n+2)y = m$$ to have solution $$gcd(n, n+2)|m$$ and $$gcd(n, n + 2)$$ is 1

From the Extended Euclidean Algorithm, given any integers $$a$$ and $$b$$ you can find integers $$s$$ and $$t$$ such that $$as+bt=gcd(a,b)$$ ($$s$$ and $$t$$ may not be unique) where $$a = n, b = (n+2)$$ and $$gcd(a, b)=1$$. Now multiply $$m$$ to both sides. you'll get $$n(sm) + (n+2)(tm) = m$$, this gives a solution $$x=sm$$, $$y =tm$$.

Here is a very similar problem which explains how to get other solutions from this

• I'm sorry, I've corrected my post, $n$ is odd. – Octavio Berlanga Jun 20 '19 at 18:06
• Hey, as gcd of two consecutive odd integers is 1. So, I changed the part gcd(n, n+2) = 2 to gcd(n, n+2) = 1. And other things a bit as now one solution is x = sm and y = tm – wild_fox Jun 20 '19 at 18:15

Hint if $$n=2k+1$$ then $$n+2=2k+3$$.

Then $$1=2k+1-2k=n-k(n+2-n)=n(1+k)-(n+2)k$$

Multiplying by $$m$$ you get the solution $$x_0=m(1+k)\\ y_0=-km$$

Now solve $$n(x-x_0)+(n+2)(y-y_0)=0$$

Hint $$\,\ 1 = n(\overbrace{x\!+\!y}^{\Large z}) + 2y \iff (z,y)\, =\, \overbrace{(1,(1\!-\!n)/2)}^{\rm particular} + \overbrace{k(-2,n)}^{\rm homogeneous}$$

• $\large {\rm by}\ \bmod n\!:\,\ 2y\equiv 1\equiv 1\!-\!n\iff y\equiv (1\!-\!n)/2 \in\Bbb Z\ \ \, {\rm by}\ n\ \rm odd\ \$ – Bill Dubuque Jun 20 '19 at 19:04