Given arbitrary integers $a,b$ , can we find in a systematic way an integer $ n$ such that $$ n^2+an+b $$ is a perfect square ?

  • 1
    $\begingroup$ Some context would be nice. $\endgroup$ – user312437 Jul 30 '16 at 18:44
  • 2
    $\begingroup$ Sometimes there is no such $n$. $\endgroup$ – André Nicolas Jul 30 '16 at 18:58
  • $\begingroup$ maybe try writing the square as $(n+c)^2$. $\endgroup$ – supinf Jul 30 '16 at 18:59
  • $\begingroup$ Case $a$ odd let $n=\left.(a-1)^2\right/4-b$ and $n^2+a n + b=\left(n+\frac{a-1}{2}\right)^2$ $\endgroup$ – Lozenges Jul 30 '16 at 19:54

If $n^2+an+b=m^2$, you can multiply everything by $4$ to get

$$4n^2+4an+4b=4m^2$$ and then complete the square to get $$ (2n+a)^2-a^2+4b=4m^2 $$

After rearranging and factoring, this is equivalent to $$ (2n+a+2m)(2n+a-2m)=a^2-4b = \Delta $$

So any such $n$ will give you a factor of $\Delta$; conversely, if we write $\Delta=pq$ as the product of two integers, we can hope to recover $n$ by solving the system of linear equations $$ 2n+a+2m=p\\ 2n+a-2m=q $$ for $m$ and $n$, but it's not guaranteed that the $m,n$ you obtain in this way will be integers.

These equations simplify into $$ n=\frac{p+q-2a}{4} \\ m=\frac{p-q}{4} $$

That is, for any given $a,b$, a procedure for finding all $n$ that work is as follows:

  • Compute $\Delta=a^2-4b$.
  • Write $\Delta$ as the product of two integers $p,q$ in all possible ways.
  • For each such factorization, compute $n=\frac{p+q-2a}{4}$, $m=\frac{p-q}{4}$. If these are both integers, this is a possible value of $n$. If they are not, it isn't.

As the other answer mentions, it is definitely possible that you will get no solutions.

For example, say $a = 5$, $b=2$. Then $\Delta=5^2-4(2)=17$, and so there are two possibilities to try:

  • Take $p=17,q=1$; then $n=\frac{17+1-10}{4}=2$, $m=\frac{17-1}{4}=4$.
  • Take $p=-17,q=-1$; then $n=\frac{-17-1-10}{4}=-7$, $m=\frac{-17-(-1)}{4}=-4$.

These correspond to the fact that $2^2+5(2)+2=16$ and $(-7)^2+5(-7)+2=16$ are perfect squares.

  • $\begingroup$ Thank you very much , That's exactly what I was looking for $\endgroup$ – Mohamed Perdu Jul 30 '16 at 19:47

I'm not sure if you want an answer (i.e., yes or no) or a systemic way to find $n$, but the short answer is no.

Whenever $a\equiv 0$ and $b\equiv 2$ mod $4$ we want a perfect square of the form $n^2+2\pmod 4.$ But a perfect square is always $0$ or $1$ mod $4$, so then $n^2+2$ is either $2$ or $3$ mod $4$. But then this cannot be a perfect square.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.