OFFSET
1,2
COMMENTS
EXAMPLE
Triangular(4) = 4*5/2 = 10. The nearest squares above and below 10 are 9 and 16. Because both 10-9=1 and 16-10=6 are triangular numbers, 4 is in the sequence.
MATHEMATICA
btnQ[n_]:=Module[{tr=(n(n+1))/2, x, y}, x=Floor[Sqrt[tr]]^2; y=Ceiling[ Sqrt[ tr]]^2; !IntegerQ[Sqrt[tr]]&&AllTrue[{Sqrt[1+8(tr-x)], Sqrt[1+ 8(y-tr)]}, OddQ]]; Join[{1}, Select[Range[205100], btnQ]] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, Aug 12 2020 *)
PROG
(Python)
import math
def isTriangular(n): # OK for relatively small n
n+=n
sr = int(math.sqrt(n))
return (n==sr*(sr+1))
for n in range(1, 264444):
tn = n*(n+1)//2
r = int(math.sqrt(tn-1))
i = tn-r*r
r = int(math.sqrt(tn))
j = (r+1)*(r+1)-tn
if isTriangular(i) and isTriangular(j): print(str(n), end=', ')
CROSSREFS
KEYWORD
nonn
AUTHOR
Alex Ratushnyak, Dec 19 2013
EXTENSIONS
Name corrected by Alex Ratushnyak, Jun 02 2016
STATUS
approved