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

A056792 Minimal number of steps to get from 0 to n by (a) adding 1 or (b) multiplying by 2.

Original entry on oeis.org

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

Views

Author

N. J. A. Sloane, Sep 01 2000

Keywords

Comments

A stopping problem: begin with n and at each stage if even divide by 2 or if odd subtract 1. That is, iterate A029578 while nonzero.
From Peter Kagey, Jul 16 2015: (Start)
The number of appearances of n in this sequence is identically A000045(n). Proof:
By application of the formula,
"a(0) = 0, a(2*n+1) = a(2*n) + 1 and a(2*n) = a(n) + 1",
it can be seen that:
{i: a(i) = n} = {2*i: a(i) = n-1, n>0} U {2*i+1: a(i) = n-2, n>1}.
Because the two sets on the left hand side share no elements:
|{i: a(i) = n}| = |{i: a(i) = n-1, n>0}| + |{i: a(i) = n-2, n>1}|
Notice that
|{i : a(i) = 1}| = |{1}| = 1 = A000045(1) and
|{i : a(i) = 2}| = |{2}| = 1 = A000045(2).
Therefore the number of appearances of n in this sequence is A000045(n). (End)

Examples

			12 = 1100 in binary, so a(12)=2+4-1=5.
		

Crossrefs

Equals A056791 - 1. The least inverse (indices of record values) of A056792 is A052955 prepended with 0. See also A014701, A115954, A056796, A056817.
Cf. A000120, A070939, A007088: base 2 sequences.
Analogous sequences with a different multiplier k: A061282 (k=3), A260112 (k=4).

Programs

  • Haskell
    c i = if i `mod` 2 == 0 then i `div` 2 else i - 1
    b 0 foldCount = foldCount
    b sheetCount foldCount = b (c sheetCount) (foldCount + 1)
    a056792 n = b n 0 -- Peter Kagey, Sep 02 2015
  • Maple
    a:= n-> (l-> nops(l)+add(i, i=l)-1)(convert(n, base, 2)):
    seq(a(n), n=0..105);  # Alois P. Heinz, Jul 16 2015
  • Mathematica
    f[ n_Integer ] := (c = 0; k = n; While[ k != 0, If[ EvenQ[ k ], k /= 2, k-- ]; c++ ]; c); Table[ f[ n ], {n, 0, 100} ]
    f[n_] := Floor@ Log2@ n + DigitCount[n, 2, 1]; Array[f, 100] (* Robert G. Wilson v, Jul 31 2012 *)
  • PARI
    a(n)=if(n<1,0,n-valuation(n!*sum(i=1,n,1/i),2))
    
  • PARI
    a(n)=if(n<1,0,1+a(if(n%2,n-1,n/2)))
    
  • PARI
    a(n)=if(n<1,0,n=binary(n);sum(i=1,#n,n[i])+#n-1) \\ Charles R Greathouse IV, Apr 11 2012
    

Formula

a(0) = 0, a(2*n+1) = a(2*n) + 1 and a(2*n) = a(n) + 1.
a(n) = n-valuation(A000254(n), 2) for n>0. - Benoit Cloitre, Mar 09 2004
a(n) = A000120(n) + A070939(n) - 1. - Michel Marcus, Jul 17 2015
a(n) = (weight of binary expansion of n) + (length of binary expansion of n) - 1.

Extensions

More terms from James Sellers, Sep 06 2000
More terms from David W. Wilson, Sep 07 2000

A014701 Number of multiplications to compute n-th power by the Chandah-sutra method.

Original entry on oeis.org

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

Views

Author

James Kilfiger (jamesk(AT)maths.warwick.ac.uk)

Keywords

Comments

In other words, number of steps to reach 1 starting from n and using the process: x -> x-1 if n is odd and x -> x/2 otherwise.
a(n) = number of 0's + twice number of 1's (disregarding the leading digit 1) in the binary expansion of n, i.e., A007088(n). - Lekraj Beedassy, May 28 2010
From Daniel Forgues, Jul 31 2012: (Start)
For the binary Fibonacci rabbits sequence (A036299) (cf. OEIS Wiki link below) we have the substitution/concatenation rule: a(n), n >= 3, may be obtained by the concatenation of a(n-1) and a(n-2), with a(1) = 0, a(2) = 1. Thus, using . (dot) as the concatenation operator, we have the recursive substitution/concatenation
a(n) = a(n-0)
a(n) = a(n-1).a(n-2)
a(n) = a(n-2).a(n-3).a(n-3).a(n-4)
a(n) = a(n-3).a(n-4).a(n-4).a(n-5).a(n-4).a(n-5).a(n-5).a(n-6)
which suggests the sequence
{0}
{1, 2}
{2, 3, 3, 4}
{3, 4, 4, 5, 4, 5, 5, 6}
whose concatenation gives A014701 (this sequence).
Number of multiplications to compute n-th power by the Chandah-sutra method, also called left-to-right binary exponentiation:
x^1 = x^( 1_2) = (x) (0 prod)
x^2 = x^( 10_2) = (x^2) (1 prod)
x^3 = x^( 11_2) = (x^2) * (x) (2 prod)
x^4 = x^( 100_2) = (x^2)^2 (2 prod)
x^5 = x^( 101_2) = (x^2)^2 * (x) (3 prod)
x^6 = x^( 110_2) = (x^2)^2 * (x^2) (3 prod)
x^7 = x^( 111_2) = (x^2)^2 * (x^2) * (x) (4 prod)
x^8 = x^(1000_2) = ((x^2)^2)^2 (3 prod) (End)
From Ya-Ping Lu, Mar 03 2021: (Start)
Index at which record m occurs is A052955(m).
First appearance of m in the sequence (or the record value m) is at n = 2^(m/2 + 1) - 1 for even m, and at n = 3*2^((m - 1)/2) - 1 for odd m.
The last appearance of m in the sequence is at n = 2^m. (End)
a(n) is the digit sum of n-1 in bijective base-2. Since the Fibonacci number F(m) can be defined as the number of ways to compose m as the sum of 1s and 2s, we get that m appears F(m) times in the sequence. - Oscar Cunningham, Apr 14 2024
Conjecture: a(n+1) is the minimal number of steps to go from 0 to n, by choosing before each step, after the first step, whether to keep the same step length or double it. The initial step length is 1. - Jean-Marc Rebert, May 15 2025

Examples

			5 -> 4 -> 2 -> 1 so 3 steps are needed to reach 1 hence a(5)=3; 9 -> 8 -> 4 -> 2 -> 1 hence a(9)=4.
		

Crossrefs

Programs

  • Haskell
    a014701 1 = 0
    a014701 n = a007953 $ a007931 (n - 1)
    -- Reinhard Zumkeller, Oct 26 2012
    
  • Maple
    A014701 := proc(n) local j,k; j := n; k := 0; while(j>1) do if j mod 2=1 then j := j-1 else j := j/2 fi; k := k+1 od end;
    # second Maple program:
    a:= n-> add(i+1, i=Bits[Split](n))-2:
    seq(a(n), n=1..128);  # Alois P. Heinz, Aug 30 2021
  • Mathematica
    a[n_] := DigitCount[n, 2] /. {x_, y_} -> 2x + y - 2; Array[a, 100] (* Robert G. Wilson v, Jul 31 2012 *)
  • PARI
    a(n)=hammingweight(n)+logint(n,2)-1 \\ Charles R Greathouse IV, Dec 29 2016
    
  • Python
    def a(n):
        if n==1:
            return 0
        return a(n//2)+1+n%2
    for i in range(1,60):
        print(a(i), end=", ")
    # Pablo Hueso Merino, Oct 28 2020

Formula

a(n) = A056792(n) - 1 = A056791(n) - 2.
a(n) = floor(log_2(n)) + (number of 1's in binary representation of n) - 1. - Corrected (- 1 at end) by Daniel Forgues, Aug 01 2012
a(2^n) = n, a(2^n-1) = 2*(n-1), and for n >= 2, log_2(n) <= a(n) <= 2*log_2(n) - 1. - Robert FERREOL, Oct 01 2014
Let u(1) = 1, u(2*n) = u(n)+1, u(2*n+1) = u(2*n)+1; then a(1) = 0 and a(n) = u(n-1). - Benoit Cloitre, Dec 19 2002
G.f.: -2/(1-x) + (1/(1-x)) * Sum_{k>=0} (2*x^2^k + x^2^(k+1))/(1+x^2^k). - Ralf Stephan, Aug 15 2003
From {0}, apply the substitution rule (n -> n+1, n+2) repeatedly, giving {{0}, {1, 2}, {2, 3, 3, 4}, {3, 4, 4, 5, 4, 5, 5, 6}, ...} and concatenate. - Daniel Forgues, Jul 31 2012
For n > 1: a(n) = A007953(A007931(n-1)). - Reinhard Zumkeller, Oct 26 2012
a(n) >= A003313(n). - Charles R Greathouse IV, Jan 03 2018
a(n) = a(floor(n/2)) + 1 + (n mod 2) for n > 1. - Pablo Hueso Merino, Oct 28 2020
a(n+1) = max_{1<=i<=n} (H(i) + H(n-i)) where H(n) denotes the Hamming weight of n (A000120(n)). See Lemma 8 in Gruber/Holzer 2021 article. - Hermann Gruber, Jun 26 2024

A189007 Number of ON cells after n generations of the 2D cellular automaton described in the comments.

Original entry on oeis.org

1, 4, 8, 16, 16, 32, 32, 64, 32, 64, 64, 128, 64, 128, 128, 256, 64, 128, 128, 256, 128, 256, 256, 512, 128, 256, 256, 512, 256, 512, 512, 1024, 128, 256, 256, 512, 256, 512, 512, 1024, 256, 512, 512, 1024, 512, 1024, 1024, 2048, 256, 512, 512, 1024, 512, 1024, 1024, 2048, 512, 1024, 1024, 2048, 1024, 2048, 2048, 4096, 256, 512, 512, 1024, 512
Offset: 1

Views

Author

John W. Layman, Apr 15 2011

Keywords

Comments

The cells are the squares of the standard infinite square grid. All cells are initially OFF and a single cell is turned ON at generation 1. At subsequent generations a cell is ON if and only if exactly one East/West neighbor was ON or exactly one North/South neighbor was ON (or BOTH of those conditions) in the previous generation.
The equivalent Mathematica cellular automaton is obtained with neighborhood weights {{0,1,0},{3,0,3},{0,1,0}}, rule number 186, and initial configuration {{1}}.
Also sequence generated by Rule 84 with neighborhood weights {{0, 2, 0}, {2, 1, 2}, {0, 2, 0}}. - Robert Price, Mar 11 2016
Conjecture: a(1) = 1; a(n) = 2^A056791(n-1) for n > 1. - Michael De Vlieger, Nov 02 2022

Crossrefs

Programs

  • Mathematica
    ca = CellularAutomaton[{186, {2, {{0, 1, 0}, {3, 0, 3}, {0, 1, 0}}}, {1, 1}}, {{{1}}, 0}, 50-1, -50]; Table[Total[ca[[n]], 2], {n, 1, 50}]

Formula

It appears that this sequence is the limit of the following process. Start with {1,4} and repeatedly perform this set of operations: (1) select the second half H of the sequence; (2) append twice the terms of H, then (3) append four times the terms of H. This gives {1,4} -> {1,4,8,16} -> {1,4,8,16,16,32,32,64} -> {1,4,8,16,16,32,32,64,32,64,64,128,64,128,128,256} -> ... This has been verified for the first 150 terms.
Comment from N. J. A. Sloane, Jul 21 2014: (Start)
It is not difficult to show that the preceding conjecture is correct. In fact one can give an explicit formula for the n-th term. At generation n >= 2, the configuration of ON cells consists of a set of concentric diamonds (see the illustration). The sizes of the diamonds are given by the (n-2)nd term of A245191. Let N = A245191(n-2) = Sum_{i>=0} b_i*2^i. Then the ON cells form a set of diamonds with edge-lengths i+2 for each b_i = 1. The i-th diamond contains 4*(i+1) ON cells, and the total number of ON cells is therefore a(n) = 4*Sum_i (i+1)*b_i. The b_i are given explicitly in A245191.
For example, if n=11, N = A245191(9) = 544 = 2^5 + 2^9, so b_5 = b_9 = 1, there are two diamonds, of side lengths 7 and 11, containing a total of 4*(6+10) = 64 = a(11) ON cells. (End)

A124108 Replace each 1 with 10 in binary representation of n.

Original entry on oeis.org

0, 2, 4, 10, 8, 18, 20, 42, 16, 34, 36, 74, 40, 82, 84, 170, 32, 66, 68, 138, 72, 146, 148, 298, 80, 162, 164, 330, 168, 338, 340, 682, 64, 130, 132, 266, 136, 274, 276, 554, 144, 290, 292, 586, 296, 594, 596, 1194, 160, 322, 324, 650, 328, 658, 660, 1322, 336, 674
Offset: 0

Views

Author

Reinhard Zumkeller, Nov 26 2006

Keywords

Comments

A070939(a(n)) = A056791(n);
A023416(a(n)) = A023416(n) + A000120(n); A000120(a(n)) = A000120(n).

Crossrefs

Programs

  • Haskell
    a124108 0 = 0
    a124108 x = 2 * (b + 1) * a124108 x' + (b * 2)
                where (x', b) = divMod x 2
    -- Reinhard Zumkeller, Mar 31 2015
  • Mathematica
    Table[FromDigits[Flatten[IntegerDigits[n,2]/.(1->{1,0})],2],{n,0,60}] (* Harvey P. Dale, May 20 2021 *)

Extensions

Offset fixed by Reinhard Zumkeller, Mar 31 2015

A178344 a(n) = Sum_i prime(i+1)^b(i) where n = Sum_{i>=0} b(i)*2^e(i) is the binary representation of n.

Original entry on oeis.org

1, 2, 4, 5, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 15, 16, 17, 18, 19, 20, 21, 22, 21, 22, 23, 24, 25, 26, 27, 28, 18, 19, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29, 30, 31, 28, 29, 30, 31, 32, 33, 34, 35, 34, 35, 36, 37, 38, 39, 40, 41, 23, 24, 25, 26, 27, 28, 29, 30, 29, 30
Offset: 0

Views

Author

Juri-Stepan Gerasimov, May 25 2010, Jan 06 2010

Keywords

Comments

a(0) = 0 might be a more logical value for the initial term. - Antti Karttunen, Sep 28 2018

Examples

			a(16)=15 because 10000 is the base-2 representation of n=16 and 11^1 + 7^0 + 5^0 + 3^0 + 2^0 = 15.
		

Crossrefs

Cf. A178562 (first differences).

Programs

  • Maple
    A178344 := proc(n)
        if n = 0 then
            dgs := [0] ;
        else
            dgs := convert(n,base,2) ;
        end if;
        add(ithprime(i)^dgs[i],i=1..nops(dgs)) ;
    end proc:
    seq(A178344(n),n=0..73) ; # R. J. Mathar, Sep 28 2018
  • Mathematica
    Array[Total@ MapIndexed[Prime[First@ #2]^#1 &, Reverse@ IntegerDigits[#, 2]] &, 74, 0] (* Michael De Vlieger, Feb 19 2019 *)
  • PARI
    a(n) = my(b=Vecrev(binary(n))); if (n==0, b=[0]); sum(i=1, #b, prime(i)^b[i]); \\ Michel Marcus, Sep 29 2018

Formula

For n >= 1, a(n) = A089625(n) + A080791(n). - Antti Karttunen, Sep 28 2018

Extensions

Offset modified, keyword:base added by R. J. Mathar, May 28 2010
Showing 1-5 of 5 results.