# For what values of $n$ is $n^2+n+2$ a power of $2$?

Working on isometric paths in hypercubes, I came up with the following simple, yet (imo) interesting problem. For what natural numbers $n$ exists a natural number $t$ such that $n^2+n+2=2^t$? The first few terms are $n=0,1,2,5,90$, and these are all below one million. Does someone have any idea how to approach this problem? I basically only want to know whether there exist infinitely many $n$ or not (maybe even that 0, 1, 2, 5, and 90 are the only possible ones).

Thanks,

Sacha

• Beyond ($n=1,t=2$), $t$ will always be odd, because $n^2 < n^2+n+2 < (n+1)^2$. Aug 22, 2012 at 15:05
• It is easily equivalent to a beautiful relation $$\sum_{i=1}^{n} i = \sum\limits_{j=1}^{t-1}2^j$$
– Ilya
Aug 22, 2012 at 15:07

To see that these solve the problem, a small preliminary transformation of your equation is useful. Rewrite it as $4n^2+4n+8=2^k$, and then as $(2n+1)^2+7=2^k$. We have arrived at the Ramanujan-Nagell equation.
• Thanks! Reading the Wikipedia article, I just realized I forgot the simplest of all solutions: $n=0$. Aug 23, 2012 at 7:07