A238456 Triangular numbers t such that t+x+y is a square, where x and y are the two squares nearest to t.
0, 2211, 5151, 1107816, 20959575, 4237107540, 1564279847151, 61066162885575, 2533192954461975, 2774988107938203, 90728963274006291, 18765679728507154152720
Offset: 1
Examples
The two squares nearest to triangular(101)=5151 are 71^2 and 72^2. Because 5151 + 71^2 + 72^2 = 15376 is a perfect square, 5151 is in the sequence.
Programs
-
Mathematica
sqQ[n_]:=Module[{c=Floor[Sqrt[n]]-1,x},x=Total[Take[SortBy[ Range[ c,c+3]^2, Abs[#-n]&],2]];IntegerQ[Sqrt[n+x]]]; Select[ Accumulate[ Range[ 0, 5000000]], sqQ] (* This will generate the first 7 terms of the sequence. To generate more, increase the second constant within the Range function, but computations will take a long time. *) (* Harvey P. Dale, May 12 2014 *)
-
Python
def isqrt(a): sr = 1 << (int.bit_length(int(a)) >> 1) while a < sr*sr: sr>>=1 b = sr>>1 while b: s = sr + b if a >= s*s: sr = s b>>=1 return sr t = i = 0 while 1: t += i i += 1 s = isqrt(t) if s*s==t: s-=1 txy = t + 2*s*(s+1) + 1 # t + s^2 + (s+1)^2 r = isqrt(txy) if r*r==txy: print(str(t), end=',')
Extensions
a(12) from Giovanni Resta, Mar 02 2014
Comments