login
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

%I #16 Jan 23 2021 01:37:00

%S 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,

%T 30,31,28,31,30,31,32,63,62,63,60,63,62,63,56,63,62,63,60,63,62,63,48,

%U 63,62,63,60,63,62,63,56,63,62,63,60,63,62,63,64,127,126

%N 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.

%H Kevin Ryde, <a href="/A340632/b340632.txt">Table of n, a(n) for n = 0..8192</a>

%F a(n) = A062383(n) - A006519(n) for n>=1.

%F a(n) = A003817(n) - A135481(n-1).

%F a(n) = n + A334045(n) (filling in 0-bits, including n=0 by taking A334045(0)=0).

%F a(n) = A142151(n-1) + 1.

%F G.f.: x/(1-x) + Sum_{k>=0} 2^k*x^(2^k)*(1/(1-x) - 1/(1-x^(2^(k+1)))).

%e n = 172 = binary 10101100;

%e a(n) = 252 = binary 11111100.

%o (PARI) a(n) = if(n, 2<<logint(n,2) - 1<<valuation(n,2), 0);

%o (Python) def a(n): return (1<<n.bit_length()) - (n&-n) if n else 0

%Y Cf. A023758 (distinct terms).

%Y Cf. A006519, A062383, A142151.

%K nonn,base,easy

%O 0,3

%A _Kevin Ryde_, Jan 13 2021