|
|
A236564
|
|
Difference between 2^(2n-1) and the nearest square.
|
|
3
|
|
|
1, -1, -4, 7, -17, 23, -89, 7, 28, 112, 448, 1792, -4417, 5503, 22012, -4633, -18532, -74128, -296512, 296863, 1187452, -1181833, -4727332, 4817239, 19268956, -17830441, -71321764, 94338007, 377352028, -9092137, -36368548, -145474192, -581896768, -2327587072, -9310348288
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,3
|
|
COMMENTS
|
The distances of the even powers 2^(2n) to their nearest squares are obviously all zero and therefore skipped.
|
|
LINKS
|
|
|
FORMULA
|
|
|
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
|
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;
|
|
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
|
|
|
STATUS
|
approved
|
|
|
|