# When is $\frac{a^2+b}{b^2+a}$ an integer?

Obviously with $a,b$ integers and $b$ can't be greater than $a$. I found some solutions, like $(12,8)$ and $(135,95)$ which give the integer $2$, and $(10,5)$ which gives $3$, but I can't find a relationship between the solutions.

• There's a lot of solutions - there are $40$ solutions with $b < a \le 100$, as checked by computer.
– user296602
Nov 29, 2017 at 23:30
• I think you need to make your question more specific. Nov 29, 2017 at 23:32
• I don't know how to make the question more specific, as my problem is just to find a relationship between the solutions. Say for example that expressions is equal to $2$, is there a way to, given a solution, find another? Nov 29, 2017 at 23:40
• I found at least one infinite class of solutions. See my answer. Nov 30, 2017 at 1:15
• A quick search in Approach0 reveals this question: Diophantine equation : $N= \frac{x^2+y}{x+y^2}$. And if there are more copies of this problem on the site, the would not be very surprising to me. Nov 30, 2017 at 6:08

For a fixed integer $k > 0$ we get solutions to $$\frac{x^2 + y}{x + y^2} = k$$ by a Pell type equation. It turns into $$(2ky -1)^2 - k (2x-k)^2 = 1 - k^3$$

You asked about $k=2.$ There are two systems of degree two linear recurrences for $w^2 - 2 v^2 = -7.$

First we have $w_n = -1, 5, 31, 181,$ with $u_n = 2, 4, 22, 128.$ The orbit relation is $$w_{n+1} = 3 w_n + 4 u_n, \; \; \; u_{n+1} = 2 w_n + 3 u_n.$$ When $w \equiv 3 \pmod 4,$ we get $y > 0$ with $2ky - 1 = w.$

We also have $w_n = 1, 11, 65, 379,$ with $u_n = 2, 8, 46, 268.$ The orbit relation is $$w_{n+1} = 3 w_n + 4 u_n, \; \; \; u_{n+1} = 2 w_n + 3 u_n.$$ When $w \equiv 3 \pmod 4,$ we get $y > 0$ with $2ky - 1 = w.$

My take on the outcome is that it is not natural to require $y > 0.$ Makes it messy.

For example, with $w = 12875,$ we get $4y = 12876,$ $y = 3219.$ Also $v = 9104,$ $2x - 2 = 9104,$ $2x = 9106,$ $x = 4553.$ Alright, $x=4553, y = 3219.$ $$\frac{x^2 + y}{y^2 + x} = \frac{4553^2 + 3219}{ 3219^2 + 4553} = \frac{20733028}{10366514} = 2$$

jagy@phobeusjunior:~$./Pell_Target_Fundamental Automorphism matrix: 3 4 2 3 Automorphism backwards: 3 -4 -2 3 3^2 - 2 2^2 = 1 w^2 - 2 v^2 = -7 Wed Nov 29 17:05:09 PST 2017 w: 1 v: 2 SEED KEEP +- w: 5 v: 4 SEED BACK ONE STEP -1 , 2 w: 11 v: 8 w: 31 v: 22 w: 65 v: 46 w: 181 v: 128 w: 379 v: 268 w: 1055 v: 746 w: 2209 v: 1562 w: 6149 v: 4348 w: 12875 v: 9104 w: 35839 v: 25342 w: 75041 v: 53062 w: 208885 v: 147704 w: 437371 v: 309268 w: 1217471 v: 860882 w: 2549185 v: 1802546 w: 7095941 v: 5017588 w: 14857739 v: 10506008 w: 41358175 v: 29244646 Wed Nov 29 17:06:09 PST 2017 w^2 - 2 v^2 = -7  • Nice. I think you have$w^n$where you mean$w_n$in a couple of cases. Can this generate solutions for any$k$? Nov 30, 2017 at 19:45 • @martycohen I see about the$w^n.$At the main question, there is now a comment with a link to an answer by Gerry Myerson, years ago. He does talk a little about$k$square, which I was ignoring. For nonsquare$k,$I am a little less sure than I was last night about infinitely many solutions; There are certainly such for the Pell thing, but the necessary congruences for integral$x,y$are not as clear as I had hoped. Nov 30, 2017 at 20:11 • @WillJagy: There are infinitely many solutions of this problem for when$k$is not square and you can see my proof here: math.stackexchange.com/questions/2802933/… Do you know any topic discussing square$k$? Jun 16, 2018 at 4:58 I have found three infinite classes of solutions to$a^2+b = n(b^2+a)$. These were derived assuming that$a$and$b$are relatively prime. All three have been verified by Wolfy. Note added later: Two other solutions are$a=5, b=2, n=3$and$a=5, b=3, n=2$. The first two are one-parameter solutions, the parameter being$m$. The first is$n=m^2+m+1,\\ a =m^3+m^2+2m+1,\\ b = m^2+1 $. The second is$n =2m^2-m+1,\\ b = 2m+1,\\ a =4m^2+1 $. The third is a two-parameter solution, the parameters being$u$and$k$.$n =u^2k^2-2uk+k+1,\\ b = u^3k^2-3u^2k+3u+uk-1,\\ a =k^3 u^4 - 4 k^2 u^3 + 2 k^2 u^2 + 6 k u^2 - 4 k u + k - 3 u+2 $. Amusingly, if we put$u=0$this gives$n=k+1, b=-1, a=k+2$which gives$\dfrac{(k+2)^2-1}{3+k} =\dfrac{k^2+4k+3}{3+k} =\dfrac{(k+3)(k+1)}{3+k} =k+1 $. This is the same as$a=k+1, b=-1, n=k$. My work that follows allows others to be derived. A more general class is$n=m^2+k,\\ a =m(2m+\dfrac{m^3+1}{k})+k,\\ b =m+\dfrac{m^3+1}{k} $where$k | (m^3+1)$(always true for$k = m+1,k = m^2-m+1$, or$m = uk-1$). Here is my derivation. If$a^2+b = n(b^2+a)$, then$a^2-na = nb^2-b$or$a(a-n) = b(nb-1)$. If$(a, b) = 1$then$nb-1 = ma$and$a-n = mb$. The following paragraph is a new addition. Note: If$m(nb-1) = a$and$m(a-n) = b$then$m$divides both$a$and$b$so$m=1$. Then$a = nb-1 =n(a-n)-1 $so$a(n-1) =n^2+1 =(n-1)(n+1)+2 $or$a = n+1+\frac{2}{n-1} $so$n=2$or$3$. If$n=2$then$a=5, b=3$; if$n=3$then$a=5, b=2$. Therefore$a = mb+n$so$nb-1 =m(mb+n) =m^2b+mn $or$b(n-m^2) =mn+1 $so that$(n-m^2)|(mn+1)$and$m^2 < n$. If$n = m^2+k$, then$mn+1 =m(m^2+k)+1 =m^3+km+1 $so that$bk = m^3+km+1 $or$b = m+\dfrac{m^3+1}{k} $. If$k | (m^3+1)$(always true for$k = m+1$and$k = m^2-m+1$), then$\begin{array}\\ a &= mb+n\\ &=m(m+\dfrac{m^3+1}{k})+m^2+k\\ &=m(2m+\dfrac{m^3+1}{k})+k\\ \end{array} $If$k = m+1$, this gives$n =m^2+k =m^2+m+1 $,$b = m+m^2-m+1 = m^2+1 $and$a =mb+n =m(m^2+1)+m^2+m+1 =m^3+m^2+2m+1 $. If$k = m^2-m+1$, this gives$n =m^2+k =m^2+m^2-m+1 =2m^2-m+1 $,$b = m+m+1 = 2m+1 $and$a =mb+n =m(2m+1)+2m^2-m+1 =4m^2+1 $. If$m = uk-1$, then$m^3 = u^3k^3-3u^2k^2+3uk-1$so$\dfrac{m^3+1}{k} =u^3k^2-3u^2k+3u $and$n =(uk-1)^2+k =u^2k^2-2uk+k+1,\\ b = u^3k^2-3u^2k+3u+uk-1,\\ a = (uk-1)(u^3k^2-3u^2k+3u+uk-1)+u^2k^2-2uk+k+1\\ \quad=k^3 u^4 - 4 k^2 u^3 + 2 k^2 u^2 + 6 k u^2 - 4 k u + k - 3 u+2 $(The expansion of$a$was done by Wolfy.) • for a fixed ratio it is a rather unpleasant Pell type thing. There will be integer solutions for each ratio$k$as the expanded Pell thing allows solution$(0,0).$Nov 30, 2017 at 1:27 • I didn't try that since this way worked. I would be interested to see your work that shows there are solutions for each possible ratio. Nov 30, 2017 at 2:18 • @martycohen: Do you know how to construct solution for$n\$ which is a perfect square? Jun 15, 2018 at 15:03

A better equation to solve in General.

$$aX^2+bX=cY^2+dY$$

As already mentioned, the task is reduced to some equivalent to the Pell equation. Actually reduced to this form.

$$p^2-acs^2=\pm1$$

Solution we write.

$$X=\pm{s(dp+cbs)}$$

$$Y=\pm{s(bp+ads)}$$

Or so.

$$X=\frac{\mp1}{a-c}((b-d)p^2-(2cb-(c+a)d)ps+c(cb-ad)s^2)$$

$$Y=\frac{\mp1}{a-c}((b-d)p^2-((a+c)b-2ad)ps+a(cb-ad)s^2)$$

Or so.

$$X^2+Y=kY^2+kX$$

$$p^2-ks^2=\pm1$$

$$X=\pm{p(kp-s)}$$

$$Y=\pm{}s(kp-s)$$