OFFSET
0,4
LINKS
Harvey P. Dale, Table of n, a(n) for n = 0..1000
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
KEYWORD
sign
AUTHOR
Alex Ratushnyak, Feb 26 2014
STATUS
approved