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-10 of 10 results.

A001855 Sorting numbers: maximal number of comparisons for sorting n elements by binary insertion.

Original entry on oeis.org

0, 1, 3, 5, 8, 11, 14, 17, 21, 25, 29, 33, 37, 41, 45, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99, 104, 109, 114, 119, 124, 129, 135, 141, 147, 153, 159, 165, 171, 177, 183, 189, 195, 201, 207, 213, 219, 225, 231, 237, 243, 249, 255, 261, 267, 273, 279, 285
Offset: 1

Views

Author

Keywords

Comments

Equals n-1 times the expected number of probes for a successful binary search in a size n-1 list.
Piecewise linear: breakpoints at powers of 2 with values given by A000337.
a(n) is the number of digits in the binary representation of all the numbers 1 to n-1. - Hieronymus Fischer, Dec 05 2006
It is also coincidentally the maximum number of comparisons for merge sort. - Li-yao Xia, Nov 18 2015

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 3, Sect 5.3.1, Eq. (3); Sect. 6.2.1 (4).
  • J. W. Moon, Topics on Tournaments. Holt, NY, 1968, p. 48.
  • N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • Tianxing Tao, On optimal arrangement of 12 points, pp. 229-234 in Combinatorics, Computing and Complexity, ed. D. Du and G. Hu, Kluwer, 1989.

Crossrefs

Programs

  • Haskell
    import Data.List (transpose)
    a001855 n = a001855_list !! n
    a001855_list = 0 : zipWith (+) [1..] (zipWith (+) hs $ tail hs) where
       hs = concat $ transpose [a001855_list, a001855_list]
    -- Reinhard Zumkeller, Jun 03 2013
    
  • Maple
    a := proc(n) local k; k := ilog2(n) + 1; 1 + n*k - 2^k end; # N. J. A. Sloane, Dec 01 2007 [edited by Peter Luschny, Nov 30 2017]
  • Mathematica
    a[n_?EvenQ] := a[n] = n + 2a[n/2] - 1; a[n_?OddQ] := a[n] = n + a[(n+1)/2] + a[(n-1)/2] - 1; a[1] = 0; a[2] = 1; Table[a[n], {n, 1, 58}] (* Jean-François Alcover, Nov 23 2011, after Pari *)
    a[n_] := n IntegerLength[n, 2] - 2^IntegerLength[n, 2] + 1;
    Table[a[n], {n, 1, 58}] (* Peter Luschny, Dec 02 2017 *)
    Accumulate[BitLength[Range[0, 100]]] (* Paolo Xausa, Sep 30 2024 *)
  • PARI
    a(n)=if(n<2,0,n-1+a(n\2)+a((n+1)\2))
    
  • PARI
    a(n)=local(m);if(n<2,0,m=length(binary(n-1));n*m-2^m+1)
    
  • Python
    def A001855(n):
        s, i, z = 0, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A001855(n) for n in range(1, 59)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A001855(n): return n*(m:=(n-1).bit_length())-(1<Chai Wah Wu, Mar 29 2023

Formula

Let n = 2^(k-1) + g, 0 <= g <= 2^(k-1); then a(n) = 1 + n*k - 2^k. - N. J. A. Sloane, Dec 01 2007
a(n) = Sum_{k=1..n}ceiling(log_2 k) = n*ceiling(log_2 n) - 2^ceiling(log_2(n)) + 1.
a(n) = a(floor(n/2)) + a(ceiling(n/2)) + n - 1.
G.f.: x/(1-x)^2 * Sum_{k>=0} x^2^k. - Ralf Stephan, Apr 13 2002
a(1)=0, for n>1, a(n) = ceiling(n*a(n-1)/(n-1)+1). - Benoit Cloitre, Apr 26 2003
a(n) = n-1 + min { a(k)+a(n-k) : 1 <= k <= n-1 }, cf. A003314. - Vladeta Jovovic, Aug 15 2004
a(n) = A061168(n-1) + n - 1 for n>1. - Hieronymus Fischer, Dec 05 2006
a(n) = A123753(n-1) - n. - Peter Luschny, Nov 30 2017

Extensions

Additional comments from M. D. McIlroy (mcilroy(AT)dartmouth.edu)

A070941 Length of binary representation of 2n+1.

Original entry on oeis.org

1, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
Offset: 0

Views

Author

N. J. A. Sloane, May 18 2002

Keywords

Comments

Sequence consists of A011782(n) n+1's. - Jon Perry, Apr 04 2004
For n > 0: a(n) = A003314(n+1) - A003314(n) = A123753(n) - A123753(n-1). - Reinhard Zumkeller, Oct 12 2006
For k >= 2, k appears 2^(k-2) times consecutively. - Bernard Schott, Jun 08 2019
Also length of binary representation of 2n. - Michel Marcus, Oct 28 2020

Crossrefs

Bisection of A070939 and also of A070940.

Programs

  • Mathematica
    Table[IntegerLength[n,2],{n,1,201,2}] (* Harvey P. Dale, May 17 2011 *)
  • PARI
    a(n)=length(binary(2*n+1))
    
  • Python
    def A070941(n): return n.bit_length()+1 # Chai Wah Wu, Mar 29 2023

Formula

Let b(1)=1, b(n) = a(n-floor(n/2)) + 1, then a(n) = b(n+1). - Benoit Cloitre, Oct 23 2002
G.f.: 1/(1-x) * (1 + Sum_{k>=0} x^2^k). - Ralf Stephan, Apr 15 2002
a(n) = ceiling(log_2(n+1)) + 1 = A029837(n+1) + 1. - Ralf Stephan, Apr 15 2002
a(n) = ceiling(average of previous entries) + 1. - Jon Perry, Apr 04 2004

A083652 Sum of lengths of binary expansions of 0 through n.

Original entry on oeis.org

1, 2, 4, 6, 9, 12, 15, 18, 22, 26, 30, 34, 38, 42, 46, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 136, 142, 148, 154, 160, 166, 172, 178, 184, 190, 196, 202, 208, 214, 220, 226, 232, 238, 244, 250, 256, 262, 268, 274, 280, 286, 292
Offset: 0

Views

Author

Reinhard Zumkeller, May 01 2003

Keywords

Comments

a(n) = A001855(n) + 1 for n > 0;
a(0) = A070939(0)=1, n > 0: a(n) = a(n-1) + A070939(n).
A030190(a(k))=1; A030530(a(k)) = k + 1.
Partial sums of A070939. - Hieronymus Fischer, Jun 12 2012
Young writes "If n = 2^i + k [...] the maximum is (i+1)(2^i+k)-2^{i+1}+2." - Michael Somos, Sep 25 2012

Examples

			G.f. = 1 + 2*x + 4*x^2 + 6*x^3 + 9*x^4 + 12*x^5 + 15*x^6 + 18*x^7 + 22*x^8 + ...
		

Crossrefs

A296349 is an essentially identical sequence.

Programs

  • Haskell
    a083652 n = a083652_list !! n
    a083652_list = scanl1 (+) a070939_list
    -- Reinhard Zumkeller, Jul 05 2012
    
  • Mathematica
    Accumulate[Length/@(IntegerDigits[#,2]&/@Range[0,60])] (* Harvey P. Dale, May 28 2013 *)
    a[n_] := (n + 1) IntegerLength[n + 1, 2] - 2^IntegerLength[n + 1, 2] + 2;Table[a[n], {n, 0, 58}] (* Peter Luschny, Dec 02 2017 *)
  • PARI
    {a(n) = my(i); if( n<0, 0, n++; i = length(binary(n)); n*i - 2^i + 2)}; /* Michael Somos, Sep 25 2012 */
    
  • PARI
    a(n)=my(i=#binary(n++));n*i-2^i+2 \\ equivalent to the above
    
  • Python
    def A083652(n):
        s, i, z = 1, n, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A083652(n) for n in range(0, 59)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A083652(n): return 2+(n+1)*(m:=(n+1).bit_length())-(1<Chai Wah Wu, Mar 01 2023

Formula

a(n) = 2 + (n+1)*ceiling(log_2(n+1)) - 2^ceiling(log_2(n+1)).
G.f.: g(x) = 1/(1-x) + (1/(1-x)^2)*Sum_{j>=0} x^2^j. - Hieronymus Fischer, Jun 12 2012; corrected by Ilya Gutkovskiy, Jan 08 2017
a(n) = A123753(n) - n. - Peter Luschny, Nov 30 2017

A061168 Partial sums of floor(log_2(k)) (= A000523(k)).

Original entry on oeis.org

0, 1, 2, 4, 6, 8, 10, 13, 16, 19, 22, 25, 28, 31, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 103, 108, 113, 118, 123, 128, 133, 138, 143, 148, 153, 158, 163, 168, 173, 178, 183, 188, 193, 198, 203, 208, 213, 218, 223, 228, 233, 238, 243, 248
Offset: 1

Views

Author

Antti Karttunen, Apr 19 2001

Keywords

Comments

Given a term b>0 of the sequence and its left hand neighbor c, the corresponding unique sequence index n with property a(n)=b can be determined by n(b)=e+(b-d*(e+1)+2*(e-1))/d, where d=b-c and e=2^d. - Hieronymus Fischer, Dec 05 2006
a(n) gives index of start of binary expansion of n in the binary Champernowne sequence A076478. - N. J. A. Sloane, Dec 14 2017
a(n) is the number of pairs in ancestor relationship (= transitive closure of the parent relationship) in all (binary) heaps on n elements. - Alois P. Heinz, Feb 13 2019

References

  • D. E. Knuth, Fundamental Algorithms, Addison-Wesley, 1973, Section 1.2.4, ex. 42(b).

Crossrefs

Programs

  • Haskell
    import Data.List (transpose)
    a061168 n = a061168_list !! n
    a061168_list = zipWith (+) [0..] (zipWith (+) hs $ tail hs) where
       hs = concat $ transpose [a001855_list, a001855_list]
    -- Reinhard Zumkeller, Jun 03 2013
    
  • Maple
    seq(add(floor(log[2](k)),k=1..j),j=1..100);
    # second Maple program:
    a:= proc(n) option remember; `if`(n<1, 0, ilog2(n)+a(n-1)) end:
    seq(a(n), n=1..80);   # Alois P. Heinz, Feb 12 2019
  • Mathematica
    Accumulate[Floor[Log[2,Range[110]]]] (* Harvey P. Dale, Jul 16 2012 *)
    a[n_] := (n+1) IntegerLength[n+1, 2] - 2^IntegerLength[n+1, 2] - n + 1;
    Table[a[n], {n, 1, 61}] (* Peter Luschny, Dec 02 2017 *)
  • PARI
    a(n)=if(n<1,0,if(n%2==0,a(n/2)+a(n/2-1)+n-1,2*a((n-1)/2)+n-1)) /* _Ralf Stephan */
    
  • PARI
    a(n)=local(k); if(n<1,0,k=length(binary(n))-1; (n+1)*k-2*(2^k-1))
    
  • PARI
    { for (n=1, 1000, k=length(binary(n))-1; write("b061168.txt", n, " ", (n + 1)*k - 2*(2^k - 1)) ) } \\ Harry J. Smith, Jul 18 2009
    
  • Python
    def A061168(n):
        s, i, z = -n , n, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A061168(n) for n in range(1, 62)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A061168(n): return (n+1)*((m:=n.bit_length())-1)-(1<Chai Wah Wu, Mar 29 2023

Formula

a(n) = A001855(n+1) - n.
a(n) = Sum_{k=1..n} floor(log_2(k)) = (n+1)*floor(log_2(n)) - 2*(2^floor(log_2(n)) - 1). - Diego Torres (torresvillarroel(AT)hotmail.com), Oct 29 2002
G.f.: 1/(1-x)^2 * Sum(k>=1, x^2^k). - Ralf Stephan, Apr 13 2002
a(n) = A123753(n) - 2*n - 1. - Peter Luschny, Nov 30 2017

A003314 Binary entropy function: a(1)=0; for n > 1, a(n) = n + min { a(k)+a(n-k) : 1 <= k <= n-1 }.

Original entry on oeis.org

0, 2, 5, 8, 12, 16, 20, 24, 29, 34, 39, 44, 49, 54, 59, 64, 70, 76, 82, 88, 94, 100, 106, 112, 118, 124, 130, 136, 142, 148, 154, 160, 167, 174, 181, 188, 195, 202, 209, 216, 223, 230, 237, 244, 251, 258, 265, 272, 279, 286, 293, 300, 307, 314, 321, 328, 335
Offset: 1

Views

Author

Keywords

Comments

Morris gives many other interesting properties of this function.
a(n) is a convex function of n. (See the Morris reference.)

Examples

			a(6) = 6 + min {1+12, 2+8, 5+5} = 6 + 10 = 16.
		

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 3, Sect 5.4.9, Eq. (19). p. 374.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Programs

  • Haskell
    a003314 n = a003314_list !! (n-1)
    a003314_list = 0 : f [0] [2..] where
       f vs (w:ws) = y : f (y:vs) ws where
         y = w + minimum (zipWith (+) vs $ reverse vs)
    -- Reinhard Zumkeller, Aug 13 2013
    
  • Maple
    A003314 := proc(n) local i,j; option remember; if n<=2 then n elif n=3 then 5 else j := 10^10; for i from 1 to n-1 do if A003314(i)+A003314(n-i) < j then j := A003314(i)+A003314(n-i); fi; od; n+j; fi; end;
  • Mathematica
    a[1] = 0; a[n_] := If[OddQ[n], n + a[(n-1)/2 + 1] + a[(n-1)/2], 2*(n/2 + a[n/2])];
    Table[a[n], {n, 1, 57}] (* Jean-François Alcover, Oct 15 2012 *)
    a[n_] := n + n IntegerLength[n, 2] - 2^IntegerLength[n, 2];
    Table[a[n], {n, 1, 57}] (* Peter Luschny, Dec 02 2017 *)
  • PARI
    a(n)=if(n<2,0,n+a(n\2)+a((n+1)\2))
    
  • PARI
    a(n)=local(m);if(n<2,0,m=length(binary(n-1));n*m-2^m+n)
    
  • Python
    def A003314(n):
        return n*int(math.log(4*n,2))-2**int(math.log(2*n,2)) # Indranil Ghosh, Feb 03 2017
    
  • Python
    def A003314(n):
        s, i, z = n-1, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A003314(n) for n in range(1, 58)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A003314(n): return n*(1+(m:=(n-1).bit_length()))-(1<Chai Wah Wu, Mar 29 2023

Formula

a(1) = 0; a(n) = n + a([n/2]) + a(n-[n/2]). (See the Morris reference.)
a(n) = A001855(n)+n-1. - Michael Somos Feb 07 2004
a(n) = n + a(floor(n/2)) + a(ceiling(n/2)) = n*floor(log_2(4n))-2^floor(log_2(2n)) = A033156(n) - n = n*A070941(n) - A062383(n). - Henry Bottomley, Jul 03 2002
a(1) = 0 and for n>1: a(n) = a(n-1) + A070941(2*n-1). Also a(n) = A123753(n-1) - 1. - Reinhard Zumkeller, Oct 12 2006
a(n) = A123753(n-1) - 1. - Peter Luschny, Nov 30 2017

A033156 a(1) = 1; for m >= 2, a(n) = a(n-1) + floor(a(n-1)/(n-1)) + 2.

Original entry on oeis.org

1, 4, 8, 12, 17, 22, 27, 32, 38, 44, 50, 56, 62, 68, 74, 80, 87, 94, 101, 108, 115, 122, 129, 136, 143, 150, 157, 164, 171, 178, 185, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, 400, 408
Offset: 1

Views

Author

N. J. A. Sloane, Jun 05 2002

Keywords

Crossrefs

Cf. A123753.

Programs

  • Maple
    A033156 := proc(n) option remember; if n=1 then 1 else A033156(n-1)+floor(A033156(n-1)/(n-1))+2; fi; end;
  • Mathematica
    a[n_] := n (2 + IntegerLength[n, 2]) - 2^IntegerLength[n, 2];
    Table[a[n], {n, 1, 59}] (* Peter Luschny, Dec 02 2017 *)
    nxt[{n_,a_}]:={n+1,a+Floor[a/n]+2}; NestList[nxt,{1,1},60][[All,2]] (* Harvey P. Dale, Nov 03 2020 *)
  • Python
    def A033156(n):
        s, i, z = 2*n-1, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A033156(n) for n in range(1, 60)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A033156(n): return n*(2+(m:=(n-1).bit_length()))-(1<Chai Wah Wu, Mar 29 2023

Formula

a(n) = n*(floor(log_2 n) + 3) - 2^((floor (log_2 n)) + 1).
a(n) = n + a(floor(n/2)) + a(ceiling(n/2)) = n + min{a(k) + a(n-k):0 < k < n} = n + A003314(n). - Henry Bottomley, Jul 03 2002
A001855(n) + 2n-1. a(n) = b(n)+1 with b(0)=0, b(2n) = b(n) + b(n-1) + 2n + 2, b(2n+1) = 2b(n) + 2n + 3. - Ralf Stephan, Oct 24 2003
a(n) = A123753(n-1) + n - 1. - Peter Luschny, Nov 30 2017

A054248 Binary entropy: a(n) = n + min { a(k)+a(n-k) : 1 <= k <= n-1 }.

Original entry on oeis.org

1, 2, 6, 8, 13, 16, 21, 24, 30, 34, 40, 44, 50, 54, 60, 64, 71, 76, 83, 88, 95, 100, 107, 112, 119, 124, 131, 136, 143, 148, 155, 160, 168, 174, 182, 188, 196, 202, 210, 216, 224, 230, 238, 244, 252, 258, 266, 272, 280, 286, 294, 300, 308, 314, 322, 328, 336
Offset: 1

Views

Author

N. J. A. Sloane, May 04 2000

Keywords

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 3, p. 374.

Crossrefs

Programs

  • Maple
    A054248 := proc(n) local i,j; option remember; if n<=2 then n else j := 10^10; for i from 1 to n-1 do if A054248(i)+A054248(n-i) < j then j := A054248(i)+A054248(n-i); fi; od; n+j; fi; end;
    # second Maple program:
    a:= proc(n) option remember; `if`(n<3, n,
          n + min(seq(a(k)+a(n-k), k=1..n/2)))
        end:
    seq(a(n), n=1..80);  # Alois P. Heinz, Aug 29 2015
  • Mathematica
    a[n_] := n + n IntegerLength[n, 2] - 2^IntegerLength[n, 2] + Mod[n, 2];
    Table[a[n], {n, 1, 54}] (* Peter Luschny, Dec 02 2017 *)
  • Python
    def A054248(n):
        s, i, z = n - (n-1) % 2, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A054248(n) for n in range(1, 55)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A054248(n): return n*(1+(m:=(n-1).bit_length()))-(1<Chai Wah Wu, Mar 29 2023

Formula

a(n) = A123753(n-1) - (n-1) mod 2. - Peter Luschny, Nov 30 2017

A097383 Minimum total number of comparisons to find each of the values 1 through n using a binary search with 3-way comparisons (less than, equal and greater than).

Original entry on oeis.org

0, 2, 3, 6, 8, 11, 13, 17, 20, 24, 27, 31, 34, 38, 41, 46, 50, 55, 59, 64, 68, 73, 77, 82, 86, 91, 95, 100, 104, 109, 113, 119, 124, 130, 135, 141, 146, 152, 157, 163, 168, 174, 179, 185, 190, 196, 201, 207, 212, 218, 223, 229, 234, 240, 245, 251, 256, 262, 267, 273
Offset: 1

Views

Author

Keywords

Comments

Optimal binary search with equality.

Examples

			a_5 = 8 = 5 + a_1 + a_3; this is the smallest example where choosing the middle value is not optimal.
		

Crossrefs

See A097384 for the sequence with a pure binary search.
A003314 is the sequence with only 2-way comparisons.
Cf. A123753.

Programs

  • Maple
    f:= proc(n) option remember;
         n+min(seq(procname(k)+procname(n-1-k),k=1..n-1))
    end proc:
    f(1):= 0: f(0):= 0:
    map(f, [$1..100]); # Robert Israel, Nov 30 2017
  • Mathematica
    a[n_] := (n+1)(1+IntegerLength[n+1,2])-2^IntegerLength[n+1,2]-Quotient[3n+1,2];
    Table[a[n], {n, 1, 60}] (* Peter Luschny, Dec 02 2017 *)
  • Python
    def A097383(n):
        s, i, z = -n//2, n, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A097383(n) for n in range(1, 61)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A097383(n): return (n+1)*(m:=n.bit_length())-(1<>1) # Chai Wah Wu, Mar 29 2023

Formula

a(n) = min_{1<=k<=n-1} n + a(k) + a(n-1-k).
a(n) = A123753(n) - floor(3*(n+1)/2). - Peter Luschny, Nov 30 2017
From Robert Israel, Nov 30 2017: (Start)
Empirical: a(n+3)-a(n+2)-a(n+1)+a(n) = 1 if n = 2^k-3 or 2^k-2 for some k, 0 otherwise.
Empirical g.f.: (2*x^2+x^3)/(1-x-x^2+x^3) + Sum_{k>=2} x^{2^k}/(1-x)^2. (End)

A295508 Triangle read by rows, related to binary partitions of n.

Original entry on oeis.org

0, 1, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 0, 5, 4, 3, 1, 6, 5, 4, 2, 7, 6, 5, 3, 8, 7, 6, 4, 0, 9, 8, 7, 5, 1, 10, 9, 8, 6, 2, 11, 10, 9, 7, 3, 12, 11, 10, 8, 4, 13, 12, 11, 9, 5, 14, 13, 12, 10, 6, 15, 14, 13, 11, 7, 16, 15, 14, 12, 8, 0, 17, 16, 15, 13, 9, 1
Offset: 0

Views

Author

Peter Luschny, Nov 30 2017

Keywords

Examples

			0;
1,   0;
2,   1,  0;
3,   2,  1;
4,   3,  2,  0;
5,   4,  3,  1;
6,   5,  4,  2;
7,   6,  5,  3;
8,   7,  6,  4, 0;
9,   8,  7,  5, 1;
10,  9,  8,  6, 2;
11, 10,  9,  7, 3;
12, 11, 10,  8, 4;
13, 12, 11,  9, 5;
14, 13, 12, 10, 6;
15, 14, 13, 11, 7;
		

Crossrefs

Cf. A123753.

Programs

  • Maple
    A295508_row := proc(n) local i, s, z; s := n; i := n-1; z := 1;
    while 0 <= i do s := s,i; i := i-z; z := z+z od; s end:
    seq(A295508_row(n), n=0..17);
    # Alternatively after formula:
    T := (n, k) -> `if`(k=0, n, n - 2^(k-1)):
    L := n -> nops(convert(n, base, 2)) - 0^n:
    T_row := n -> seq(T(n,k), k=0..L(n)):
    seq(T_row(n), n=0..17);

Formula

Let L(n) = (length of binary representation of n) - 0^n then
T(n, k) = n if k=0 else n - 2^(k-1) for n >= 0 and 0 <= k <= L(n).
Sum_{k=0..L(n)} T(n,k) = A123753(n-1) for n>=1.

A295513 a(n) = n*bil(n) - 2^bil(n) where bil(0) = 0 and bil(n) = floor(log_2(n)) + 1 for n>0.

Original entry on oeis.org

-1, -1, 0, 2, 4, 7, 10, 13, 16, 20, 24, 28, 32, 36, 40, 44, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93, 98, 103, 108, 113, 118, 123, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182, 188, 194, 200, 206, 212, 218, 224, 230, 236, 242, 248, 254, 260, 266, 272, 278
Offset: 0

Views

Author

Peter Luschny, Dec 02 2017

Keywords

Crossrefs

Programs

  • Maple
    A295513 := proc(n) local i, s, z; s := -1; i := n-1; z := 1;
    while 0 <= i do s := s+i; i := i-z; z := z+z od; s end:
    seq(A295513(n), n=0..57);
  • Mathematica
    a[n_] := n IntegerLength[n, 2] - 2^IntegerLength[n, 2];
    Table[a[n], {n, 0, 58}]
  • Python
    def A295513(n): return n*(m:=(n-1).bit_length())-(1<Chai Wah Wu, Mar 29 2023

Formula

A001855(n) = a(n) + 1.
A033156(n) = a(n) + 2n.
A003314(n) = a(n) + n.
A083652(n) = a(n+1) + 2.
A061168(n) = a(n+1) - n + 1.
A123753(n) = a(n+1) + n + 2.
A097383(n) = a(n+1) - div(n-1, 2).
A054248(n) = a(n) + n + rem(n, 2).
Showing 1-10 of 10 results.