OFFSET
1,3
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
FORMULA
Let b(1) = 0, b(2) = 1, otherwise b(2*n-1) = b(n-1) and b(2*n) = b(n).
Let c(1) = 0, c(2) = 1, otherwise c(2*n-1) = c(n-1)+1 and c(2*n) = c(n).
Then for n >= 2, a(2*n-1) = 2*c(2*n-1) - b(2*n-1) and a(2*n) = 2*c(2*n).
EXAMPLE
The fourth base-2 palindrome is 5 = 101_2, so a(4) = 1+0+1 = 2.
MAPLE
b:= proc(n) option remember;
procname(floor(n/2)) end proc;
b(1):= 0; b(2):= 1;
c:= proc(n) option remember;
procname(floor(n/2)) + (n mod 2) end proc;
c(1):= 0; c(2):= 1;
A043261:= n -> 2*c(n) - (n mod 2)*b(n);
A043261(2):= 1; # Robert Israel, Apr 06 2014
PROG
(Python)
def A043261(n):
if n == 1: return 0
a = 1<<(l:=n.bit_length()-2)
m = a|(n&a-1)
return (m.bit_count()<<1) - (0 if a&n else m&1) # Chai Wah Wu, Jun 13 2024
CROSSREFS
KEYWORD
nonn,base
AUTHOR
EXTENSIONS
edited by Robert Israel, Apr 06 2014
STATUS
approved