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.

A080079 Least number causing the longest carry sequence when adding numbers <= n to n in binary representation.

Original entry on oeis.org

1, 2, 1, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47
Offset: 1

Views

Author

Reinhard Zumkeller, Jan 26 2003

Keywords

Comments

T(n,k) < T(n,a(n)) = A070940(n) for 1 <= k < a(n) and T(n,k) <= T(n,a(n)) for a(n) <= k <= n, where T is defined as in A080080.
a(n) gives the distance from n to the nearest 2^t > n. - Ctibor O. Zizka, Apr 09 2020

Crossrefs

Programs

  • Haskell
    a080079 n = (length $ takeWhile (< a070940 n) (a080080_row n)) + 1
    -- Reinhard Zumkeller, Apr 22 2013
    
  • Magma
    [-n+2*2^Floor(Log(n)/Log(2)): n in [1..80]]; // Vincenzo Librandi, Dec 01 2016
    
  • Maple
    # Alois P. Heinz observes in A327489:
    A080079 := n -> 1 + Bits:-Nor(n, n):
    # Likewise:
    A080079 := n -> 1 + Bits:-Nand(n, n):
    seq(A080079(n), n=1..81); # Peter Luschny, Sep 23 2019
  • Mathematica
    Flatten@Table[Nest[Most[RotateRight[#]] &, Range[n], n - 1], {n, 30}] (* Birkas Gyorgy, Feb 07 2011 *)
    Table[FromDigits[(IntegerDigits[n, 2] /. {0 -> 1, 1 -> 0}), 2] +
    1, {n, 30}] (* Birkas Gyorgy, Feb 07 2011 *)
    Table[BitXor[n, 2^IntegerPart[Log[2, n] + 1] - 1] + 1, {n, 30}] (* Birkas Gyorgy, Feb 07 2011 *)
    Table[2 2^Floor[Log[2, n]] - n, {n, 30}] (* Birkas Gyorgy, Feb 07 2011 *)
    Flatten@Table[Reverse@Range[2^n], {n, 0, 4}] (* Birkas Gyorgy, Feb 07 2011 *)
  • Python
    def A080079(n): return (1 << n.bit_length())-n # Chai Wah Wu, Jun 30 2022

Formula

From Benoit Cloitre, Feb 22 2003: (Start)
a(n) = A004755(n) - 2*n.
a(n) = -n + 2*2^floor(log(n)/log(2)). (End)
From Ralf Stephan, Jun 02 2003: (Start)
a(n) = n iff n = 2^k, otherwise a(n) = A035327(n-1).
a(n) = A062383(n) - n. (End)
a(0) = 0, a(2*n) = 2*a(n), a(2*n+1) = 2*a(n)-1 + 2*[n==0]. - Ralf Stephan, Jan 04 2004
a(n) = A240769(n,1); A240769(n, a(n)) = 1. - Reinhard Zumkeller, Apr 13 2014
a(n) = n + 1 - A006257(n). - Reinhard Zumkeller, Apr 14 2014