OFFSET
0,3
COMMENTS
From Trevor Green (green(AT)snoopy.usask.ca), Nov 26 2003: (Start)
a(n)/n has an accumulation point at x exactly when x is in the interval [1, 2]. Proof: Clearly n <= a(n) < 2n. Let b(n) = a(n)/n, then b(n) must always lie in [1,2) and all the accumulation points of the sequence must lie in [1,2]. We shall show that every such number is an accumulation point.
First, consider any d-bit integer n. Suppose that z of these bits are 0. Let n' be the (d+z)-bit integer whose first d bits are the same as those of n and whose remaining bits are all 1. Then a(n') will have to be the (d+z)-bit integer whose first d bits are all 1 and whose last z bits are all 0.
Thus n' = (n+1)*2^z-1; a(n') = (2^d-1)2^z; and b(n') = (2^d-1)/(n+1) + epsilon, where 0 < epsilon < 2^(1-d). So to get an accumulation point x, we just choose n(d) to be the d-bit integer such that (2^d-1)/(n(d)+1) < x <= (2^d-1)/n(d), or equivalently, n(d) = floor((2^d-1)/x). If x lies in [1,2), then n(d) will always be a d-bit number for sufficiently large d.
Then n'(d) yields an increasing subsequence of the integers for which b(n'(d)) converges to x. For x = 2, choose n(d) = 2^(d-1), which is always a d-bit number; then b(n'(d)) = (2^d-1)/(2^(d-1)+1) + epsilon = 2 + epsilon', where epsilon' also heads for 0 as d blows up. This proves the claim.
(End)
LINKS
Seiichi Manyama, Table of n, a(n) for n = 0..8191 (terms 0..1023 from T. D. Noe)
FORMULA
a(n+1) = a(floor(n/2))*2 + (n mod 2)*(2^floor(log_2(n)) - a(floor(n/2))); a(0)=0.
a(0)=0, a(1)=1, a(2n) = 2a(n), a(2n+1) = a(n) + 2^floor(log_2(n)). - Ralf Stephan, Oct 05 2003
a(n) = 2^(floor(log_2(n)) + 1) * (1 - 2^(-d(n))) where d(n) = digit sum of base-2 expansion of n. - Trevor G. Hyde (thyde12(AT)amherst.edu), Jul 14 2008
n <= a(n) < 2n. - Charles R Greathouse IV, Aug 07 2024
EXAMPLE
a(20)=24, as 20='10100' and 24 is the greatest number having two 1's and three 0's: 17='10001', 18='10010', 20='10100' and 24='11000'.
MAPLE
a:= n-> Bits[Join](sort(Bits[Split](n))):
seq(a(n), n=0..100); # Alois P. Heinz, Jun 26 2021
MATHEMATICA
f[n_] := Module[{idn=IntegerDigits[n, 2], o, l}, l=Length[idn]; o=Count[idn, 1]; FromDigits[Join[Table[1, {o}], Table[0, {l-o}]], 2]]; Table[f[i], {i, 0, 70}]
ln[n_] := Module[{idn=IntegerDigits[n, 2], len, zer}, len=Length[idn]; zer=Count[idn, 0]; FromDigits[Join[Table[1, {len-zer}], Table[0, {zer}]], 2]]; Table[ln[i], {i, 0, 70}]
a[z_] := 2^(Floor[Log[2, z]] + 1) * (1 - 2^(-Sum[k, {k, IntegerDigits[n, 2]}])) Column[Table[a[p], {p, 500}], Right] (* Trevor G. Hyde (thyde12(AT)amherst.edu), Jul 14 2008 *)
Table[FromDigits[ReverseSort[IntegerDigits[n, 2]], 2], {n, 0, 70}] (* Harvey P. Dale, Mar 13 2023 *)
PROG
(Haskell)
a073138 n = a038573 n * a080100 n -- Reinhard Zumkeller, Jan 16 2012
(PARI) a(n) = fromdigits(vecsort(binary(n), , 4), 2); \\ Michel Marcus, Sep 26 2018
(Python)
def a(n): return int("".join(sorted(bin(n)[2:], reverse=True)), 2)
print([a(n) for n in range(71)]) # Michael S. Branicky, Jun 27 2021
CROSSREFS
KEYWORD
AUTHOR
Reinhard Zumkeller, Jul 16 2002
STATUS
approved