login
A340632
a(n) in binary is a run of 1-bits from the most significant 1-bit of n down to the least significant 1-bit of n, inclusive.
4
0, 1, 2, 3, 4, 7, 6, 7, 8, 15, 14, 15, 12, 15, 14, 15, 16, 31, 30, 31, 28, 31, 30, 31, 24, 31, 30, 31, 28, 31, 30, 31, 32, 63, 62, 63, 60, 63, 62, 63, 56, 63, 62, 63, 60, 63, 62, 63, 48, 63, 62, 63, 60, 63, 62, 63, 56, 63, 62, 63, 60, 63, 62, 63, 64, 127, 126
OFFSET
0,3
FORMULA
a(n) = A062383(n) - A006519(n) for n>=1.
a(n) = A003817(n) - A135481(n-1).
a(n) = n + A334045(n) (filling in 0-bits, including n=0 by taking A334045(0)=0).
a(n) = A142151(n-1) + 1.
G.f.: x/(1-x) + Sum_{k>=0} 2^k*x^(2^k)*(1/(1-x) - 1/(1-x^(2^(k+1)))).
EXAMPLE
n = 172 = binary 10101100;
a(n) = 252 = binary 11111100.
PROG
(PARI) a(n) = if(n, 2<<logint(n, 2) - 1<<valuation(n, 2), 0);
(Python) def a(n): return (1<<n.bit_length()) - (n&-n) if n else 0
CROSSREFS
Cf. A023758 (distinct terms).
Sequence in context: A265363 A319651 A373185 * A074846 A120225 A247798
KEYWORD
nonn,base,easy
AUTHOR
Kevin Ryde, Jan 13 2021
STATUS
approved