OFFSET
1,3
COMMENTS
The distances of the even powers 2^(2n) to their nearest squares are obviously all zero and therefore skipped.
LINKS
Vincenzo Librandi, Table of n, a(n) for n = 1..500
FORMULA
If A201125(n) < A238454(n), a(n) = A201125(n), otherwise a(n) = -A238454(n). [Negative terms are for cases where the nearest square is above 2^(2n-1), not below it.] - Antti Karttunen, Feb 27 2014
EXAMPLE
a(1) = 2^1 - 1^2 = 1.
a(2) = 2^3 - 3^2 = -1.
a(3) = 2^5 - 6^2 = 32 - 36 = -4.
MAPLE
A236564 := proc(n)
local x, sq, lo, hi ;
x := 2^(2*n-1) ;
sq := isqrt(x) ;
lo := sq^2 ;
hi := (sq+1)^2 ;
if abs(x-lo) < abs(x-hi) then
x-lo ;
else
x-hi ;
end if;
end proc: # R. J. Mathar, Mar 13 2014
MATHEMATICA
Table[2^n - Round[Sqrt[2^n]]^2, {n, 1, 79, 2}] (* Alonso del Arte, Feb 23 2014 *)
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(47):
nn = 2**(2*n+1)
a = isqrt(nn)
d1 = nn - a*a
d2 = (a+1)**2 - nn
if d2 < d1: d1 = -d2
print(str(d1), end=', ')
CROSSREFS
KEYWORD
sign,easy
AUTHOR
Alex Ratushnyak, Feb 23 2014
STATUS
approved