James Tanton asks: “An old question: Triang nmbrs:1,3,6,10,15,.. For every triangular nmbr is there a second larger triang nmbr so that their product is square?”
Answer: yes! I thought “hey, this is a question I can answer in my head!” but didn’t get further than noticing that 1 times 36 is 36. Then I got home and wrote some Python. (You’ll probably see this blog’s language of choice shifting from R to Python, mostly because I’m using Python at work and this gives me a chance to practice.)
import math
def tri(n):
return n*(n+1)/2
def is_square(integer):
root = math.sqrt(integer)
if int(root + 0.5) ** 2 == integer:
return True
else:
return False
def next_tri(n, m):
z = False
i = 0
while ((not z) and (i < m)):
i += 1
if is_square(tri(n)*tri(n+i)):
return n+i
return 0
def answers(n, m):
list = [0]*n
for i in range(1, n+1):
list[i-1] = next_tri(i, m)
return list
The first function here, tri, outputs triangular numbers; the second tells you if its input is a square, and is taken from this Stackoverflow answer. next_tri is where the “magic” happens; it outputs the index of the first triangular number k greater than n such that tri(n)*tri(k) is a square. But since this loop may, a priori, be infinite, we cut this off at k = n+m. If none of tri(n)tri(n+1), tri(n)tri(n+2), …, tri(n)tri(n+m) are square, it outputs 0. Finally, calling answers(n,m) outputs the list answers(1,m), answers(2,m), …, answers(n,m).
If you call answers(10, 1000) you get the output
[8, 24, 48, 80, 120, 168, 224, 49, 360, 440].
So, for example, tri(1) tri(8) = (1)(36) = 36 is square, namely 62; tri(2) tri(24) = (3)(300) = 900 = 302; and so on. If you ignore the eighth element of this list and stare for a moment, you start to see a quadratic! Namely,
appears to be a square. And in fact we can write
This is an identity that’s not hard to prove, and answers Tanton’s question in the affirmative, but I think it’s hard to discover without computation. Of course you could do the computation by hand, but it’s 2012.
But this identity tells us that — and this is true, but 288 is not the smallest solution to the problem that Tanton originally posed. In fact the computer search gives . When do smaller solutions exist?