OFFSET
0,2
COMMENTS
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..10000
FORMULA
a(n) = max(m | A006995(m) <= n);
a(A006995(n)) = n;
A006995(a(n)) <= n, equality holds true iff n is a binary palindrome;
Let p = A206913(n), m = floor(log_2(p)) and p>2, then:
a(n) = (((5-(-1)^m)/2) + sum_{k=1..floor(m/2)} (floor(p/2^k) mod 2)/2^k)) * 2^floor(m/2).
a(n) = (1/2)*((6-(-1)^m)*2^floor(m/2) - 1 - sum_{k=1..floor(m/2)} (-1)^floor(p/2^k) * 2^(floor(m/2)-k))).
a(n) = (5-(-1)^m) * 2^floor(m/2)/2 - 3*sum_{k=2..floor(m/2)} (floor(p/2^k) * 2^floor(m/2)/2^k) + (floor(p/2) * 2^floor(m/2)/2 - 2*floor((p/2) * 2^floor(m/2)) * floor((m-1)/m+1/2).
Partial sums S(n) = sum_{k=0..n} a(k):
S(n) = (n+1)*a(n) - A206920(a(n)).
G.f.: g(x) = (1+x+x^3+sum_{j>=1} x^(3*2^j)*(f_j(x)+f_j(1/x)))/(1-x), where the f_j(x) are defined as follows:
f_1(x) = x, and for j>1,
f_j(x) = x^3*product_{k=1..floor((j-1)/2)} (1+x^b(j,k)), where b(j,k)=2^(floor((j-1)/2)-k)*((3+(-1)^j)*2^(2*k+1)+4) for k>1, and b(j,1)=(2+(-1)^j)*2^(floor((j-1)/2)+1).
EXAMPLE
a(1)=2 since 2 is the index number of the greatest binary palindrome <= 1;
a(5)=4 since there are only 4 binary palindromes (namely 0,1,3 and 5) which are less than or equal to 5;
MATHEMATICA
A178225[n_]:=Boole[PalindromeQ[IntegerDigits[n, 2]]];
Accumulate[Array[A178225, 100, 0]] (* Paolo Xausa, Oct 15 2023 *)
PROG
(Python)
def A206915(n):
l = n.bit_length()
k = l+1>>1
return (n>>l-k)-(int(bin(n)[k+1:1:-1] or '0', 2)>(n&(1<<k)-1))+(1<<k-1+(l&1^1)) # Chai Wah Wu, Jul 24 2024
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Hieronymus Fischer, Feb 15 2012
STATUS
approved