login
A238455
Difference between 4^n and the nearest triangular number.
3
0, 1, 1, -2, 3, -11, 1, -87, -167, -306, -500, -552, 688, -3041, -579, 20854, 37075, 55618, 37108, -222296, -147729, 891994, 602155, -3523022, -2228805, 14811346, 11792251, -47737262, -1136517, 375078994, 741065851, 1445763154, 2746052116, 4910207464, 7492827856
OFFSET
0,4
LINKS
FORMULA
a(n) = (1/2)*(-t^2 - t + 2*4^n), where t = floor(sqrt(2*4^n)) after formula in A053616. - Michel Marcus, Jun 16 2022
EXAMPLE
a(0) = 1 - 1 = 0.
a(1) = 4 - 3 = 1.
a(2) = 16 - 15 = 1.
a(3) = 64 - 66 = -2.
a(4) = 256 - 253 = 3.
MATHEMATICA
db4n[n_]:=Module[{c=4^n, tr, t1, t2, d1, d2}, tr=Floor[(Sqrt[8c+1]-1)/2]; t1= (tr (tr+1))/ 2; t2=((tr+1)(tr+2))/2; d1=c-t1; d2=c-t2; If[d1<Abs[ d2], d1, d2]]; Array[ db4n, 40, 0] (* Harvey P. Dale, Jul 02 2019 *)
PROG
(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
for n in range(77):
nn = 4**n
s = isqrt(2*nn)
if s*(s+1)//2 > nn: s-=1
d1 = nn - s*(s+1)//2
d2 = (s+1)*(s+2)//2 - nn
if d2 < d1: d1 = -d2
print(str(d1), end=', ')
(PARI) a(n) = my(p=4^n, t=sqrtint(2*p)); (-t^2 - t + 2*p)/2; \\ Michel Marcus, Jun 16 2022
CROSSREFS
Absolute values give the other bisection of A233327.
Sequence in context: A070239 A002443 A111788 * A098929 A073098 A201267
KEYWORD
sign
AUTHOR
Alex Ratushnyak, Feb 26 2014
STATUS
approved