How would you do this question?

63 Views Asked by At

"The first two numbers that are both squares and triangles are 1 and 36. Find the next one and, if possible, the one after that. Can you figure out an efficient way to find triangular–square numbers? Do you think that there are infinitely many?"

Thanks.

1

There are 1 best solutions below

2
On BEST ANSWER

$${t_n} = \sum\limits_{k = 1}^n k = 1 + 2 + 3 + \cdots + n = \frac{{n\left( {n + 1} \right)}}{2} = n-th{\text{ triangular number}}$$ $${s_m} = {\text{m-th square number}} = {m^2}$$ $${s_m} = {t_n} \Rightarrow \frac{1}{2}n\left( {n + 1} \right) = {m^2}$$ $$\frac{1}{2}{\left( {n + \frac{1}{2}} \right)^2} = \frac{1}{2}\left( {{n^2} + n + \frac{1}{4}} \right) = \frac{1}{2}\left( {{n^2} + n} \right) + \frac{1}{8}$$ $$\frac{1}{2}n\left( {n + 1} \right) = \frac{1}{2}\left( {{n^2} + n} \right) = \frac{1}{2}{\left( {n + \frac{1}{2}} \right)^2} - \frac{1}{8} = {m^2}$$ $$\frac{1}{2}{\left( {n + \frac{1}{2}} \right)^2} - {m^2} = \frac{1}{8}$$ $$4{\left( {n + \frac{1}{2}} \right)^2} - 8{m^2} = 1$$ $$2 \cdot \left( {n + \frac{1}{2}} \right) \cdot 2\left( {n + \frac{1}{2}} \right) - 8{m^2} = 1$$ $${\left( {2n + 1} \right)^2} - 8{m^2} = 1$$ $${\left( {2n + 1} \right)^2} - 2 \cdot {\left( {2m} \right)^2} = 1$$ $$\boxed{w \equiv 2n + 1}$$ $$\boxed{z \equiv 2m}$$ $$\boxed{{w^2} - 2{z^2} = 1}$$

Finding numbers that satisfy the last equation above isn't all that simple... so I found the first numbers that are both triangular and square using python

import pandas as pd
import numpy as np
triangular_and_square = []
for n in np.arange(1,10000):
    w = 2*n + 1
    for m in np.arange(1,10000):
        z = 2*m
        if w*w - 2*z*z - 1 == 0:
            triangular_and_square.append([m*m,m,n])
output_dataframe = pd.DataFrame(triangular_and_square,
                                 columns = ["Square (m-squared) + Triangular","m","n"], 
                                 index = [1,2,3,4,5,6])

print(output_dataframe)

Code output

$$\begin{array}{*{20}{c}} & {{\rm{Square (}}{m^2}){\rm{ and Triangular}}}&& m&& n& \\ \hline & 1&& 1&& 1& \\ & {36}&& 6&& 8& \\ & {1225}&& {35}&& {49}& \\ & {41616}&& {204}&& {288}& \\ & {1413721}&& {1189}&& {1681}& \\ & {48024900}&& {6930}&& {9800}& \end{array}$$