OFFSET
0,3
COMMENTS
LINKS
FORMULA
a(n) < 2^k for any n < 2^k.
If this sequence is grouped by the bit length of n into an irregular array with rows of lengths 1, 1, 2, 4, 8..., it becomes A088208 (resp. A362160) when each row is reversed and changed by a constant: a(n) = A088208(m, p-k) + p = A362160(m, p-k) + 2^m, where p = 2^m-1, m = floor(log_2(n)), k = n - 2^m, i.e., where n is the k-th number with m+1 bits in the binary expansion. - Andrei Zabolotskii, Dec 22 2025
EXAMPLE
For n = 23,
- the binary representation of 23 is "10111",
- the corresponding run lengths are (1, 1, 3),
- so a(23) = 2^(1-1) + 2^(1+1-1) + 2^(1+1+3-1) = 19.
MATHEMATICA
a[n_] := If[n == 0, 0, 2^((Length /@ Split[IntegerDigits[n, 2]] // Accumulate)-1) // Total];
Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Jan 02 2022 *)
PROG
(PARI) a(n) = { my (v=0); while (n, my (w=valuation(n+n%2, 2)); n\=2^w; v=2^w*(1+v)); v/2 }
CROSSREFS
KEYWORD
AUTHOR
Rémy Sigrist, Feb 23 2021
STATUS
approved
