[seqfan] Re: a question about triangular numbers

Richard Mathar mathar at strw.leidenuniv.nl
Tue Dec 8 19:28:23 CET 2009

```On behalf of http://list.seqfan.eu/pipermail/seqfan/2009-December/003182.html :

If a(n)=the largest of the three triangular numbers x,y,z
of partitioning n=x+y+z into any three triangulare numbers, I get the more
irregular:

1, 1, 3, 3, 3, 6, 6, 6, 6, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15, 10,
21, 21, 21, 21, 21, 15, 21, 28, 28, 28, 28, 28, 21, 28, 28, 36, 36, 36,
36, 36, 28, 36, 36, 28, 45, 45, 45, 45, 45, 28,...
with "drop-outs"

Maple:
# The triangular numbers
A000027 := proc(n)
option remember;
n*(n+1)/2 ;
end proc:
# test if the argument is a triangular number
isA000027 := proc(n)
issqr(1+8*n) ;
end proc:
# calculate the maximum in the set Ta+Tb+Tc=n, any Ta, Tb, Tc of A000027
ltn := proc(n)
local res, ai,bi,Ta,Tb,Tc ;
res := -1 ;
# loop Ta over all triangular numbers
for ai from 0 do
Ta := A000027(ai) ;
if Ta > n then
break;
else
# loop Tb over all triangular numbers
for bi from ai do
Tb := A000027(bi) ;
if Ta+Tb > n then
break;
else
# Tc the remainder to sum to n
Tc := n-Ta-Tb ;
if isA000027(Tc) then
res := max(res, Ta, Tb, Tc) ;
# printf("%d = %d + %d + %d\n",n,Ta,Tb,Tc) ;
end if;
end if ;
end do ;
end if ;
end do;
return res;
end proc:

seq(ltn(n),n=1..50) ;

```