login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A335599
Sequence is limit_{k->oo} s_k, where s_k = s_{k-1}, s_{k-1}[k-1] + 2^(k-1), ..., s_{k-1}[end] + 2^(k-1) starting with s_0 = s_0[0..1] = 0,0.
1
0, 0, 1, 1, 2, 3, 3, 5, 5, 6, 7, 7, 9, 10, 11, 11, 13, 13, 14, 15, 15, 18, 19, 19, 21, 21, 22, 23, 23, 25, 26, 27, 27, 29, 29, 30, 31, 31, 35, 35, 37, 37, 38, 39, 39, 41, 42, 43, 43, 45, 45, 46, 47, 47, 50, 51, 51, 53, 53, 54, 55, 55, 57, 58, 59, 59, 61, 61
OFFSET
0,5
COMMENTS
In binary 0, 0, 1, 1, 10, 11, 11, 101, 101, 110, 111, 111, 1001, 1010, 1011, 1101, 1110, 1111, 1111, 10010, 10011, 10011, 10101, ...
a(n) = m is the smallest solution to m + bitcount(m) = n or n-1. So a(n) = smaller nonzero of A228086(n) and A228086(n-1) (for n>=2). - Kevin Ryde, Jul 05 2020
LINKS
FORMULA
a(n) + bitcount(a(n)) + A334820(n) = n for n>=0.
MAPLE
s:= proc(n) option remember; `if`(n=0, [0, 0][], (l->
[l[], map(x-> x+2^(n-1), l[n..-1])[]][])([s(n-1)]))
end:
s(7); # gives 136 = A005126(7) terms; # Alois P. Heinz, Jul 04 2020
MATHEMATICA
a[n_] := If[n == 0, 0,
Module[{m = n, k = Floor@Log2[n]}, m -= k + 1; While[k >= 0,
If[BitGet[m, k] == 0, m++;
If[BitGet[m, k] == 1, Return[m-1]]]; k--]; m]];
Table[a[n], {n, 0, 67}] (* Jean-François Alcover, May 30 2022, after Kevin Ryde *)
PROG
(PARI) a(n) = { if(n, my(k=logint(n, 2)); n-=k+1;
while(k>=0, if(!bittest(n, k), n++; if(bittest(n, k), return(n-1))); k--));
n; } \\ Kevin Ryde, Jul 05 2020
CROSSREFS
Sequence in context: A023816 A353714 A159237 * A227065 A010761 A320840
KEYWORD
nonn
AUTHOR
Richard Aime Blavy, Jun 15 2020
STATUS
approved