cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-4 of 4 results.

A073138 Largest number having in its binary representation the same number of 0's and 1's as n.

Original entry on oeis.org

0, 1, 2, 3, 4, 6, 6, 7, 8, 12, 12, 14, 12, 14, 14, 15, 16, 24, 24, 28, 24, 28, 28, 30, 24, 28, 28, 30, 28, 30, 30, 31, 32, 48, 48, 56, 48, 56, 56, 60, 48, 56, 56, 60, 56, 60, 60, 62, 48, 56, 56, 60, 56, 60, 60, 62, 56, 60, 60, 62, 60, 62, 62, 63, 64, 96, 96, 112, 96, 112, 112
Offset: 0

Views

Author

Reinhard Zumkeller, Jul 16 2002

Keywords

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)

Examples

			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'.
		

Crossrefs

Cf. A030109.
Cf. A038573.
Decimal equivalent of A221714. - N. J. A. Sloane, Jan 26 2013

Programs

  • Haskell
    a073138 n = a038573 n * a080100 n  -- Reinhard Zumkeller, Jan 16 2012
    
  • 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 *)
  • 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
    
  • Python
    def A073138(n): return (m:=1<>n.bit_count()) # Chai Wah Wu, Aug 18 2025

Formula

a(n+1) = a(floor(n/2))*2 + (n mod 2)*(2^floor(log_2(n)) - a(floor(n/2))); a(0)=0.
A023416(a(n)) = A023416(n), A000120(a(n)) = A000120(n).
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
a(n) = A038573(n) * A080100(n). - Reinhard Zumkeller, Jan 16 2012
n <= a(n) < 2n. - Charles R Greathouse IV, Aug 07 2024

A073137 a(n) is the least number whose binary representation has the same number of 0's and 1's as n.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 5, 7, 8, 9, 9, 11, 9, 11, 11, 15, 16, 17, 17, 19, 17, 19, 19, 23, 17, 19, 19, 23, 19, 23, 23, 31, 32, 33, 33, 35, 33, 35, 35, 39, 33, 35, 35, 39, 35, 39, 39, 47, 33, 35, 35, 39, 35, 39, 39, 47, 35, 39, 39, 47, 39, 47, 47, 63, 64, 65, 65, 67, 65, 67, 67, 71, 65
Offset: 0

Views

Author

Reinhard Zumkeller, Jul 16 2002

Keywords

Comments

A023416(a(n)) = A023416(n), A000120(a(n)) = A000120(n).
Fixed points are { 0 } union { A099627 }. - Alois P. Heinz, Jan 30 2025

Examples

			a(20)=17, as 20='10100' and 17 is the smallest number having two 1's and three 0's: 17='10001', 18='10010', 20='10100' and 24='11000'.
		

Crossrefs

Programs

  • Maple
    a:= n-> (l-> (2^nops(l)+2^add(i, i=l))/2-1)(Bits[Split](n)):
    seq(a(n), n=0..100);  # Alois P. Heinz, Jun 26 2021
  • Mathematica
    lnb[n_]:=Module[{sidn=Sort[IntegerDigits[n,2]]},FromDigits[Join[{1}, Most[ sidn]],2]]; Join[{0},Array[lnb,80]] (* Harvey P. Dale, Aug 04 2014 *)
  • PARI
    a(n) = if(n==0,0, 1<Kevin Ryde, Jun 26 2021
  • Python
    def a(n):
        b = bin(n)[2:]; z = b.count('0'); w = len(b) - z
        return int('1'*(w > 0) + '0'*z + '1'*(w-1), 2)
    print([a(n) for n in range(73)]) # Michael S. Branicky, Jun 26 2021
    
  • Python
    def a(n): b = bin(n)[2:]; return int(b[0] + "".join(sorted(b[1:])), 2)
    print([a(n) for n in range(73)]) # Michael S. Branicky, Jun 26 2021
    

Formula

a(0)=0, a(1)=1; for n > 1, let C = 2^(floor(log_2(n))-1) = A072376(n); then a(n) = a(n-C) + C if n < 3*C; otherwise a(n) = 2*a(n - 2*C) + 1. [corrected by Jon E. Schoenfield, Jun 27 2021]
For n > 0: a(n) = (2^(A000120(n) - 1)) * (2^A023416(n) + 1) - 1. - Corrected by Michel Marcus, Nov 15 2013

A073139 Difference between the largest and smallest number having in binary representation the same number of 0's and 1's as n.

Original entry on oeis.org

0, 0, 0, 0, 0, 1, 1, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 7, 7, 9, 7, 9, 9, 7, 7, 9, 9, 7, 9, 7, 7, 0, 0, 15, 15, 21, 15, 21, 21, 21, 15, 21, 21, 21, 21, 21, 21, 15, 15, 21, 21, 21, 21, 21, 21, 15, 21, 21, 21, 15, 21, 15, 15, 0, 0, 31, 31, 45, 31, 45, 45, 49, 31, 45, 45, 49, 45, 49, 49, 45, 31
Offset: 0

Views

Author

Reinhard Zumkeller, Jul 16 2002

Keywords

Comments

a(n) = A073138(n) - A073137(n).

Crossrefs

Programs

  • Mathematica
    d[n_]:=Module[{idn2=IntegerDigits[n,2]},FromDigits[Sort[idn2,#1>#2&],2]- FromDigits[ RotateRight[Sort[idn2],1],2]]; Array[d,90,0] (* Harvey P. Dale, Oct 22 2011 *)

A073141 Product of the largest and smallest number having in binary representation the same number of 0's and 1's as n.

Original entry on oeis.org

0, 1, 4, 9, 16, 30, 30, 49, 64, 108, 108, 154, 108, 154, 154, 225, 256, 408, 408, 532, 408, 532, 532, 690, 408, 532, 532, 690, 532, 690, 690, 961, 1024, 1584, 1584, 1960, 1584, 1960, 1960, 2340, 1584, 1960, 1960, 2340, 1960, 2340, 2340, 2914, 1584, 1960
Offset: 0

Views

Author

Reinhard Zumkeller, Jul 16 2002

Keywords

Comments

a(n) = A073137(n) * A073138(n).

Crossrefs

Programs

  • Mathematica
    pls[n_]:=With[{d=FromDigits[#,2]&/@Select[Permutations[IntegerDigits[n,2]],#[[1]]==1&]},Max[d]Min[d]]; Join[{0},Array[pls,50]] (* Harvey P. Dale, May 29 2025 *)
Showing 1-4 of 4 results.