Yesterday, James Tanton posted a fun little problem on Twitter:

So, 2 is one more than , and 8 is one less than 9=2^3$, and Dr. Tanton wants to know if there are any other powers of two that are within one unit of a perfect square.

While this problem may not have any “real-life relevance”, it demonstrates what I describe as the power and creativity of mathematics. Among the *infinite* number of powers of two, how can someone know for certain if any others are or are not within one unit of a perfect square? No one will ever be able to see every number in the list of powers of two, but *variables* and *mathematics* give you the tools to deal with all possibilities at once.

For this problem, let *D* and *N* be positive integers. Translated into mathematical language, Dr. Tanton’s problem is equivalent to asking if there are values of *D* and *N* for which . With a single equation in two unknowns, this is where observation and creativity come into play. I suspect there may be more than one way to approach this, but my solution follows. Don’t read any further if you want to solve this for yourself.

**WARNING: SOLUTION ALERT!**

Because *D* and *N* are positive integers, the left side of , is always even. That means , and therefore *N* must be odd.

Because *N* is odd, I know for some whole number *k*. Rewriting our equation gives , and the right side equals either or .

Factoring the first expression gives . Notice that this is the product of two consecutive integers, *k* and , and therefore one of these factors (even though I don’t know which one) must be an odd number. The only odd number that is a factor of a power of two is 1, so either or . Now, and , the two solutions Dr. Tanton gave. No other possibilities are possible from this expression, no matter how far down the list of powers of two you want to go.

But what about the other expression? Factoring again gives . The expression in parentheses must be odd because its first two terms are both multiplied by 2 (making them even) and then one is added (making the overall sum odd). Again, 1 is the only odd factor of a power of two, and this happens in this case only when , repeating a solution from above.

Because no other algebraic solutions are possible, the two solutions Dr. Tanton gave in the problem statement are the only two times *in the entire universe of perfect squares and powers of two* where elements of those two lists are within a single unit of each other.

Math is sweet.