When $f(x)=\frac{-b^2m-ba+ax}{-mx-bm-a}$ is an integer $a,b,m,x$ are positive integers.
For which $x>0$ is $f(x)$ an integer?
$$f(x)=\frac{-b^2m-ba+ax}{-mx-bm-a}$$
I been trying to play with it, I changed it to:
$$\frac{b^2m-a\left(b+x\right)}{a+m\left(b+x\right)}$$
And then I been trying to say:
$$a+m\left(b+x\right)| b^2m-a\left(b+x\right) $$
$$a+m\left(b+x\right)| (a+m\left(b+x\right))(b+x)$$
So
$$a+m\left(b+x\right)| b^2m-a\left(b+x\right)+ (a+m\left(b+x\right))(b+x)$$
$$a+m\left(b+x\right)| m\left(\left(b+x\right)^2+b^2\right)$$
But I don't see how it helps, so please help me.
 A: Here is a partial answer: Note that
\begin{eqnarray*}
f(x)&=&\frac{b^2m+ba-ax}{bm+a+mx}=\frac{b^2m+ba+bmx-bmx-ax-mx^2+mx^2}{bm+a+mx}\\
&=&\frac{(b-x)(bm+a+mx)+mx^2}{bm+a+mx}=b-x+\frac{mx^2}{bm+a+mx}.
\end{eqnarray*}
So $f(x)$ is an integer if and only if $\frac{mx^2}{bm+a+mx}$ is. This means there is a positive integer $k$ such that
$$mx^2=k(bm+a+mx)=kbm+ka+kmx.$$
In particular $ka=mc$ for some positive integer $c$, so we get
$$mx^2-kmx-kbm+mc=0\qquad\text{ and hence }\qquad x^2-kx-(kb+c)=0.$$
So by the quadratic formula
$$x=\frac{k}{2}\pm\frac{1}{2}\sqrt{k^2+4kb+4c},$$
is an integer. This is an integer if and only if $k^2+4kb+4c$ is a square. So the question is then:

Given positive integers $b$ and $c$, for which positive integers $k$ is 
  $k^2+4kb+4c$ a square?

A: For every even $x>0$ we have that $f(x)$ is not an integer for all $a,b,m$. To see this, chose an even $x$ and take $a=b=m=x$. Then 
$$
f(x)=\frac{-x^3}{-2x^2-x}=\frac{x^2}{2x+1}.
$$
Because $x^2$ is even, and $2x+1$ is odd, the fraction cannot be an integer. Similarly, for $x$ odd, take $a=b=x$ and $m=x+1$ to see that
$$
f(x)=\frac{x^2+x}{2x+3},
$$
which cannot be an integer for $x$ odd.
A: I want to continue Serves answer in a different way.
Solving $mx^2=kbm+ka+kmx$ yealds:
$$x_{1,2} = \frac{mk\pm\sqrt{m^2k^2+4m\left(bmk+ak\right)}}{2m}=$$
$$\frac{km+\sqrt{km}\sqrt{\left(km+4\left(bm+a\right)\right)}}{2m}$$
One of the conditions for $x$ to be integer is when $\sqrt{km}$ is an integer or km = $(km+4(bm+a)$, but since $a,b,m>0$ the second part doesn't hold, so $\sqrt{km}$ needs to be integer, and this only happens when $k = m$ or $k$ is one of $m$ multipliers in such way that $km$ is a perfect square, or in other words(a bit weaker condition) $gcm(k,m)>1$
So it sounds like in order to solve this, all you have to do is factor $m$ and hope that $km+4\left(bm+a\right)$ is an integer
A: So we have $$nx+bn+a\mid  b^2m+ba-ax$$ Since $$nx+bn+a\mid  a(nx+bn+a)$$ and $$nx+bn+a\mid  n(b^2m+ba-ax)$$ we have $$nx+bn+a\mid  a(nx+bn+a)+n(b^2m+ba-ax)$$
so $$nx+bn+a\mid  2abn+a^2+b^2mn$$
thus $x= {d-a-bn \over n}$ where $d$ divides $2abn+a^2+b^2mn$. But be careful, not all $x$ are necessary integer, you must eliminate some of them.
