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 47 results. Next

A000120 1's-counting sequence: number of 1's in binary expansion of n (or the binary weight of n).

Original entry on oeis.org

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

Views

Author

Keywords

Comments

The binary weight of n is also called Hamming weight of n. [The term "Hamming weight" was named after the American mathematician Richard Wesley Hamming (1915-1998). - Amiram Eldar, Jun 16 2021]
a(n) is also the largest integer such that 2^a(n) divides binomial(2n, n) = A000984(n). - Benoit Cloitre, Mar 27 2002
To construct the sequence, start with 0 and use the rule: If k >= 0 and a(0), a(1), ..., a(2^k-1) are the first 2^k terms, then the next 2^k terms are a(0) + 1, a(1) + 1, ..., a(2^k-1) + 1. - Benoit Cloitre, Jan 30 2003
An example of a fractal sequence. That is, if you omit every other number in the sequence, you get the original sequence. And of course this can be repeated. So if you form the sequence a(0 * 2^n), a(1 * 2^n), a(2 * 2^n), a(3 * 2^n), ... (for any integer n > 0), you get the original sequence. - Christopher.Hills(AT)sepura.co.uk, May 14 2003
The n-th row of Pascal's triangle has 2^k distinct odd binomial coefficients where k = a(n) - 1. - Lekraj Beedassy, May 15 2003
Fixed point of the morphism 0 -> 01, 1 -> 12, 2 -> 23, 3 -> 34, 4 -> 45, etc., starting from a(0) = 0. - Robert G. Wilson v, Jan 24 2006
a(n) is the number of times n appears among the mystery calculator sequences: A005408, A042964, A047566, A115419, A115420, A115421. - Jeremy Gardiner, Jan 25 2006
a(n) is the number of solutions of the Diophantine equation 2^m*k + 2^(m-1) + i = n, where m >= 1, k >= 0, 0 <= i < 2^(m-1); a(5) = 2 because only (m, k, i) = (1, 2, 0) [2^1*2 + 2^0 + 0 = 5] and (m, k, i) = (3, 0, 1) [2^3*0 + 2^2 + 1 = 5] are solutions. - Hieronymus Fischer, Jan 31 2006
The first appearance of k, k >= 0, is at a(2^k-1). - Robert G. Wilson v, Jul 27 2006
Sequence is given by T^(infinity)(0) where T is the operator transforming any word w = w(1)w(2)...w(m) into T(w) = w(1)(w(1)+1)w(2)(w(2)+1)...w(m)(w(m)+1). I.e., T(0) = 01, T(01) = 0112, T(0112) = 01121223. - Benoit Cloitre, Mar 04 2009
For n >= 2, the minimal k for which a(k(2^n-1)) is not multiple of n is 2^n + 3. - Vladimir Shevelev, Jun 05 2009
Triangle inequality: a(k+m) <= a(k) + a(m). Equality holds if and only if C(k+m, m) is odd. - Vladimir Shevelev, Jul 19 2009
a(k*m) <= a(k) * a(m). - Robert Israel, Sep 03 2023
The number of occurrences of value k in the first 2^n terms of the sequence is equal to binomial(n, k), and also equal to the sum of the first n - k + 1 terms of column k in the array A071919. Example with k = 2, n = 7: there are 21 = binomial(7,2) = 1 + 2 + 3 + 4 + 5 + 6 2's in a(0) to a(2^7-1). - Brent Spillner (spillner(AT)acm.org), Sep 01 2010, simplified by R. J. Mathar, Jan 13 2017
Let m be the number of parts in the listing of the compositions of n as lists of parts in lexicographic order, a(k) = n - length(composition(k)) for all k < 2^n and all n (see example); A007895 gives the equivalent for compositions into odd parts. - Joerg Arndt, Nov 09 2012
From Daniel Forgues, Mar 13 2015: (Start)
Just tally up row k (binary weight equal k) from 0 to 2^n - 1 to get the binomial coefficient C(n,k). (See A007318.)
0 1 3 7 15
0: O | . | . . | . . . . | . . . . . . . . |
1: | O | O . | O . . . | O . . . . . . . |
2: | | O | O O . | O O . O . . . |
3: | | | O | O O O . |
4: | | | | O |
Due to its fractal nature, the sequence is quite interesting to listen to.
(End)
The binary weight of n is a particular case of the digit sum (base b) of n. - Daniel Forgues, Mar 13 2015
The mean of the first n terms is 1 less than the mean of [a(n+1),...,a(2n)], which is also the mean of [a(n+2),...,a(2n+1)]. - Christian Perfect, Apr 02 2015
a(n) is also the largest part of the integer partition having viabin number n. The viabin number of an integer partition is defined in the following way. Consider the southeast border of the Ferrers board of the integer partition and consider the binary number obtained by replacing each east step with 1 and each north step, except the last one, with 0. The corresponding decimal form is, by definition, the viabin number of the given integer partition. "Viabin" is coined from "via binary". For example, consider the integer partition [2, 2, 2, 1]. The southeast border of its Ferrers board yields 10100, leading to the viabin number 20. - Emeric Deutsch, Jul 20 2017
a(n) is also known as the population count of the binary representation of n. - Chai Wah Wu, May 19 2020

Examples

			Using the formula a(n) = a(floor(n / floor_pow4(n))) + a(n mod floor_pow4(n)):
  a(4) = a(1) + a(0) = 1,
  a(8) = a(2) + a(0) = 1,
  a(13) = a(3) + a(1) = 2 + 1 = 3,
  a(23) = a(1) + a(7) = 1 + a(1) + a(3) = 1 + 1 + 2 = 4.
_Gary W. Adamson_ points out (Jun 03 2009) that this can be written as a triangle:
  0,
  1,
  1,2,
  1,2,2,3,
  1,2,2,3,2,3,3,4,
  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
  1,2,2,3,2,3,...
where the rows converge to A063787.
From _Joerg Arndt_, Nov 09 2012: (Start)
Connection to the compositions of n as lists of parts (see comment):
[ #]:   a(n)  composition
[ 0]:   [0]   1 1 1 1 1
[ 1]:   [1]   1 1 1 2
[ 2]:   [1]   1 1 2 1
[ 3]:   [2]   1 1 3
[ 4]:   [1]   1 2 1 1
[ 5]:   [2]   1 2 2
[ 6]:   [2]   1 3 1
[ 7]:   [3]   1 4
[ 8]:   [1]   2 1 1 1
[ 9]:   [2]   2 1 2
[10]:   [2]   2 2 1
[11]:   [3]   2 3
[12]:   [2]   3 1 1
[13]:   [3]   3 2
[14]:   [3]   4 1
[15]:   [4]   5
(End)
		

References

  • Jean-Paul Allouche and Jeffrey Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, p. 119.
  • Donald E. Knuth, The Art of Computer Programming, vol. 4A, Combinatorial Algorithms, Section 7.1.3, Problem 41, p. 589. - N. J. A. Sloane, Aug 03 2012
  • Manfred R. Schroeder, Fractals, Chaos, Power Laws. W.H. Freeman, 1991, p. 383.
  • 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).

Crossrefs

The basic sequences concerning the binary expansion of n are this one, A000788, A000069, A001969, A023416, A059015, A007088.
Partial sums see A000788. For run lengths see A131534. See also A001792, A010062.
Number of 0's in n: A023416 and A080791.
a(n) = n - A011371(n).
Sum of digits of n written in bases 2-16: this sequence, A053735, A053737, A053824, A053827, A053828, A053829, A053830, A007953, A053831, A053832, A053833, A053834, A053835, A053836.
This is Guy Steele's sequence GS(3, 4) (see A135416).
Cf. A230952 (boustrophedon transform).
Cf. A070939 (length of binary representation of n).

Programs

  • Fortran
    c See link in A139351
    
  • Haskell
    import Data.Bits (Bits, popCount)
    a000120 :: (Integral t, Bits t) => t -> Int
    a000120 = popCount
    a000120_list = 0 : c [1] where c (x:xs) = x : c (xs ++ [x,x+1])
    -- Reinhard Zumkeller, Aug 26 2013, Feb 19 2012, Jun 16 2011, Mar 07 2011
    
  • Haskell
    a000120 = concat r
        where r = [0] : (map.map) (+1) (scanl1 (++) r)
    -- Luke Palmer, Feb 16 2014
    
  • Magma
    [Multiplicity(Intseq(n, 2), 1): n in [0..104]]; // Marius A. Burtea, Jan 22 2020
    
  • Magma
    [&+Intseq(n, 2):n in [0..104]]; // Marius A. Burtea, Jan 22 2020
  • Maple
    A000120 := proc(n) local w,m,i; w := 0; m := n; while m > 0 do i := m mod 2; w := w+i; m := (m-i)/2; od; w; end: wt := A000120;
    A000120 := n -> add(i, i=convert(n,base,2)): # Peter Luschny, Feb 03 2011
    with(Bits): p:=n->ilog2(n-And(n,n-1)): seq(p(binomial(2*n,n)),n=0..200) # Gary Detlefs, Jan 27 2019
  • Mathematica
    Table[DigitCount[n, 2, 1], {n, 0, 105}]
    Nest[Flatten[# /. # -> {#, # + 1}] &, {0}, 7] (* Robert G. Wilson v, Sep 27 2011 *)
    Table[Plus @@ IntegerDigits[n, 2], {n, 0, 104}]
    Nest[Join[#, # + 1] &, {0}, 7] (* IWABUCHI Yu(u)ki, Jul 19 2012 *)
    Log[2, Nest[Join[#, 2#] &, {1}, 14]] (* gives 2^14 term, Carlos Alves, Mar 30 2014 *)
  • PARI
    {a(n) = if( n<0, 0, 2*n - valuation((2*n)!, 2))};
    
  • PARI
    {a(n) = if( n<0, 0, subst(Pol(binary(n)), x ,1))};
    
  • PARI
    {a(n) = if( n<1, 0, a(n\2) + n%2)}; /* Michael Somos, Mar 06 2004 */
    
  • PARI
    a(n)=my(v=binary(n));sum(i=1,#v,v[i]) \\ Charles R Greathouse IV, Jun 24 2011
    
  • PARI
    a(n)=norml2(binary(n)) \\ better use {A000120=hammingweight}. - M. F. Hasler, Oct 09 2012, edited Feb 27 2020
    
  • PARI
    a(n)=hammingweight(n) \\ Michel Marcus, Oct 19 2013
    (Common Lisp) (defun floor-to-power (n pow) (declare (fixnum pow)) (expt pow (floor (log n pow)))) (defun enabled-bits (n) (if (< n 4) (n-th n (list 0 1 1 2)) (+ (enabled-bits (floor (/ n (floor-to-power n 4)))) (enabled-bits (mod n (floor-to-power n 4)))))) ; Stephen K. Touset (stephen(AT)touset.org), Apr 04 2007
    
  • Python
    def A000120(n): return bin(n).count('1') # Chai Wah Wu, Sep 03 2014
    
  • Python
    import numpy as np
    A000120 = np.array([0], dtype="uint8")
    for bitrange in range(25): A000120 = np.append(A000120, np.add(A000120, 1))
    print([A000120[n] for n in range(0, 105)]) # Karl-Heinz Hofmann, Nov 07 2022
    
  • Python
    def A000120(n): return n.bit_count() # Requires Python 3.10 or higher. - Pontus von Brömssen, Nov 08 2022
    
  • Python
    # Also see links.
    
  • SageMath
    def A000120(n):
        if n <= 1: return Integer(n)
        return A000120(n//2) + n%2
    [A000120(n) for n in range(105)]  # Peter Luschny, Nov 19 2012
    
  • SageMath
    def A000120(n) : return sum(n.digits(2)) # Eric M. Schmidt, Apr 26 2013
    
  • Scala
    (0 to 127).map(Integer.bitCount()) // _Alonso del Arte, Mar 05 2019
    

Formula

a(0) = 0, a(2*n) = a(n), a(2*n+1) = a(n) + 1.
a(0) = 0, a(2^i) = 1; otherwise if n = 2^i + j with 0 < j < 2^i, a(n) = a(j) + 1.
G.f.: Product_{k >= 0} (1 + y*x^(2^k)) = Sum_{n >= 0} y^a(n)*x^n. - N. J. A. Sloane, Jun 04 2009
a(n) = a(n-1) + 1 - A007814(n) = log_2(A001316(n)) = 2n - A005187(n) = A070939(n) - A023416(n). - Henry Bottomley, Apr 04 2001; corrected by Ralf Stephan, Apr 15 2002
a(n) = log_2(A000984(n)/A001790(n)). - Benoit Cloitre, Oct 02 2002
For n > 0, a(n) = n - Sum_{k=1..n} A007814(k). - Benoit Cloitre, Oct 19 2002
a(n) = n - Sum_{k>=1} floor(n/2^k) = n - A011371(n). - Benoit Cloitre, Dec 19 2002
G.f.: (1/(1-x)) * Sum_{k>=0} x^(2^k)/(1+x^(2^k)). - Ralf Stephan, Apr 19 2003
a(0) = 0, a(n) = a(n - 2^floor(log_2(n))) + 1. Examples: a(6) = a(6 - 2^2) + 1 = a(2) + 1 = a(2 - 2^1) + 1 + 1 = a(0) + 2 = 2; a(101) = a(101 - 2^6) + 1 = a(37) + 1 = a(37 - 2^5) + 2 = a(5 - 2^2) + 3 = a(1 - 2^0) + 4 = a(0) + 4 = 4; a(6275) = a(6275 - 2^12) + 1 = a(2179 - 2^11) + 2 = a(131 - 2^7) + 3 = a(3 - 2^1) + 4 = a(1 - 2^0) + 5 = 5; a(4129) = a(4129 - 2^12) + 1 = a(33 - 2^5) + 2 = a(1 - 2^0) + 3 = 3. - Hieronymus Fischer, Jan 22 2006
A fixed point of the mapping 0 -> 01, 1 -> 12, 2 -> 23, 3 -> 34, 4 -> 45, ... With f(i) = floor(n/2^i), a(n) is the number of odd numbers in the sequence f(0), f(1), f(2), f(3), f(4), f(5), ... - Philippe Deléham, Jan 04 2004
When read mod 2 gives the Morse-Thue sequence A010060.
Let floor_pow4(n) denote n rounded down to the next power of four, floor_pow4(n) = 4 ^ floor(log4 n). Then a(0) = 0, a(1) = 1, a(2) = 1, a(3) = 2, a(n) = a(floor(n / floor_pow4(n))) + a(n % floor_pow4(n)). - Stephen K. Touset (stephen(AT)touset.org), Apr 04 2007
a(n) = n - Sum_{k=2..n} Sum_{j|n, j >= 2} (floor(log_2(j)) - floor(log_2(j-1))). - Hieronymus Fischer, Jun 18 2007
a(n) = A138530(n, 2) for n > 1. - Reinhard Zumkeller, Mar 26 2008
a(A077436(n)) = A159918(A077436(n)); a(A000290(n)) = A159918(n). - Reinhard Zumkeller, Apr 25 2009
a(n) = A063787(n) - A007814(n). - Gary W. Adamson, Jun 04 2009
a(n) = A007814(C(2n, n)) = 1 + A007814(C(2n-1, n)). - Vladimir Shevelev, Jul 20 2009
For odd m >= 1, a((4^m-1)/3) = a((2^m+1)/3) + (m-1)/2 (mod 2). - Vladimir Shevelev, Sep 03 2010
a(n) - a(n-1) = { 1 - a(n-1) if and only if A007814(n) = a(n-1), 1 if and only if A007814(n) = 0, -1 for all other A007814(n) }. - Brent Spillner (spillner(AT)acm.org), Sep 01 2010
a(A001317(n)) = 2^a(n). - Vladimir Shevelev, Oct 25 2010
a(n) = A139351(n) + A139352(n) = Sum_k {A030308(n, k)}. - Philippe Deléham, Oct 14 2011
From Hieronymus Fischer, Jun 10 2012: (Start)
a(n) = Sum_{j = 1..m+1} (floor(n/2^j + 1/2) - floor(n/2^j)), where m = floor(log_2(n)).
General formulas for the number of digits >= d in the base p representation of n, where 1 <= d < p: a(n) = Sum_{j = 1..m+1} (floor(n/p^j + (p-d)/p) - floor(n/p^j)), where m=floor(log_p(n)); g.f.: g(x) = (1/(1-x))*Sum_{j>=0} (x^(d*p^j) - x^(p*p^j))/(1-x^(p*p^j)). (End)
a(n) = A213629(n, 1) for n > 0. - Reinhard Zumkeller, Jul 04 2012
a(n) = A240857(n,n). - Reinhard Zumkeller, Apr 14 2014
a(n) = log_2(C(2*n,n) - (C(2*n,n) AND C(2*n,n)-1)). - Gary Detlefs, Jul 10 2014
Sum_{n >= 1} a(n)/2n(2n+1) = (gamma + log(4/Pi))/2 = A344716, where gamma is Euler's constant A001620; see Sondow 2005, 2010 and Allouche, Shallit, Sondow 2007. - Jonathan Sondow, Mar 21 2015
For any integer base b >= 2, the sum of digits s_b(n) of expansion base b of n is the solution of this recurrence relation: s_b(n) = 0 if n = 0 and s_b(n) = s_b(floor(n/b)) + (n mod b). Thus, a(n) satisfies: a(n) = 0 if n = 0 and a(n) = a(floor(n/2)) + (n mod 2). This easily yields a(n) = Sum_{i = 0..floor(log_2(n))} (floor(n/2^i) mod 2). From that one can compute a(n) = n - Sum_{i = 1..floor(log_2(n))} floor(n/2^i). - Marek A. Suchenek, Mar 31 2016
Sum_{k>=1} a(k)/2^k = 2 * Sum_{k >= 0} 1/(2^(2^k)+1) = 2 * A051158. - Amiram Eldar, May 15 2020
Sum_{k>=1} a(k)/(k*(k+1)) = A016627 = log(4). - Bernard Schott, Sep 16 2020
a(m*(2^n-1)) >= n. Equality holds when 2^n-1 >= A000265(m), but also in some other cases, e.g., a(11*(2^2-1)) = 2 and a(19*(2^3-1)) = 3. - Pontus von Brömssen, Dec 13 2020
G.f.: A(x) satisfies A(x) = (1+x)*A(x^2) + x/(1-x^2). - Akshat Kumar, Nov 04 2023

A070939 Length of binary representation of n.

Original entry on oeis.org

1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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, 7, 7, 7, 7, 7, 7, 7, 7, 7
Offset: 0

Views

Author

N. J. A. Sloane, May 18 2002

Keywords

Comments

Zero is assumed to be represented as 0.
For n>1, n appears 2^(n-1) times. - Lekraj Beedassy, Apr 12 2006
a(n) is the permanent of the n X n 0-1 matrix whose (i,j) entry is 1 iff i=1 or i=j or i=2*j. For example, a(4)=3 is per([[1, 1, 1, 1], [1, 1, 0, 0], [0, 0, 1, 0], [0, 1, 0, 1]]). - David Callan, Jun 07 2006
a(n) is the number of different contiguous palindromic bit patterns in the binary representation of n; for examples, for 5=101_2 the bit patterns are 0, 1, 101; for 7=111_2 the corresponding patterns are 1, 11, 111; for 13=1101_2 the patterns are 0, 1, 11, 101. - Hieronymus Fischer, Mar 13 2012
A103586(n) = a(n + a(n)); a(A214489(n)) = A103586(A214489(n)). - Reinhard Zumkeller, Jul 21 2012
Number of divisors of 2^n that are <= n. - Clark Kimberling, Apr 21 2019

Examples

			8 = 1000 in binary has length 4.
		

References

  • G. Everest, A. van der Poorten, I. Shparlinski and T. Ward, Recurrence Sequences, Amer. Math. Soc., 2003; see esp. p. 255.
  • L. Levine, Fractal sequences and restricted Nim, Ars Combin. 80 (2006), 113-127.

Crossrefs

A029837(n+1) gives the length of binary representation of n without the leading zeros (i.e., when zero is represented as the empty sequence). For n > 0 this is equal to a(n).
This is Guy Steele's sequence GS(4, 4) (see A135416).
Cf. A083652 (partial sums).

Programs

  • Haskell
    a070939 n = if n < 2 then 1 else a070939 (n `div` 2) + 1
    a070939_list = 1 : 1 : l [1] where
       l bs = bs' ++ l bs' where bs' = map (+ 1) (bs ++ bs)
    -- Reinhard Zumkeller, Jul 19 2012, Jun 07 2011
    
  • Magma
    A070939:=func< n | n eq 0 select 1 else #Intseq(n, 2) >; [ A070939(n): n in [0..104] ]; // Klaus Brockhaus, Jan 13 2011
    
  • Maple
    A070939 := n -> `if`(n=0, 1, ilog2(2*n)):
    seq(A070939(n), n=0..104); # revised by Peter Luschny, Aug 10 2017
  • Mathematica
    Table[Length[IntegerDigits[n, 2]], {n, 0, 50}] (* Stefan Steinerberger, Apr 01 2006 *)
    Join[{1},IntegerLength[Range[110],2]] (* Harvey P. Dale, Aug 18 2013 *)
    a[ n_] := If[ n < 1, Boole[n == 0], BitLength[n]]; (* Michael Somos, Jul 10 2018 *)
  • PARI
    {a(n) = if( n<1, n==0, #binary(n))} /* Michael Somos, Aug 31 2012 */
    
  • PARI
    apply( {A070939(n)=exponent(n+!n)+1}, [0..99]) \\ works for negative n and is much faster than the above. - M. F. Hasler, Jan 04 2014, updated Feb 29 2020
    
  • Python
    def a(n): return len(bin(n)[2:])
    print([a(n) for n in range(105)]) # Michael S. Branicky, Jan 01 2021
    
  • Python
    def A070939(n): return 1 if n == 0 else n.bit_length() # Chai Wah Wu, May 12 2022
  • Sage
    def A070939(n) : return (2*n).exact_log(2) if n != 0 else 1
    [A070939(n) for n in range(100)] # Peter Luschny, Aug 08 2012
    

Formula

a(0) = 1; for n >= 1, a(n) = 1 + floor(log_2(n)) = 1 + A000523(n).
G.f.: 1 + 1/(1-x) * Sum(k>=0, x^2^k). - Ralf Stephan, Apr 12 2002
a(0)=1, a(1)=1 and a(n) = 1+a(floor(n/2)). - Benoit Cloitre, Dec 02 2003
a(n) = A000120(n) + A023416(n). - Lekraj Beedassy, Apr 12 2006
a(2^m + k) = m + 1, m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Mar 14 2017
a(n) = A113473(n) if n>0.

Extensions

a(4) corrected by Antti Karttunen, Feb 28 2003

A007088 The binary numbers (or binary words, or binary vectors, or binary expansion of n): numbers written in base 2.

Original entry on oeis.org

0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111
Offset: 0

Views

Author

Keywords

Comments

List of binary numbers. (This comment is to assist people searching for that particular phrase. - N. J. A. Sloane, Apr 08 2016)
Or, numbers that are sums of distinct powers of 10.
Or, numbers having only digits 0 and 1 in their decimal representation.
Complement of A136399; A064770(a(n)) = a(n). - Reinhard Zumkeller, Dec 30 2007
From Rick L. Shepherd, Jun 25 2009: (Start)
Nonnegative integers with no decimal digit > 1.
Thus nonnegative integers n in base 10 such that kn can be calculated by normal addition (i.e., n + n + ... + n, with k n's (but not necessarily k + k + ... + k, with n k's)) or multiplication without requiring any carry operations for 0 <= k <= 9. (End)
For n > 1: A257773(a(n)) = 10, numbers that are Belgian-k for k=0..9. - Reinhard Zumkeller, May 08 2015
For any integer n>=0, find the binary representation and then interpret as decimal representation giving a(n). - Michael Somos, Nov 15 2015
N is in this sequence iff A007953(N) = A101337(N). A028897 is a left inverse. - M. F. Hasler, Nov 18 2019
For n > 0, numbers whose largest decimal digit is 1. - Stefano Spezia, Nov 15 2023

Examples

			a(6)=110 because (1/2)*((1-(-1)^6)*10^0 + (1-(-1)^3)*10^1 + (1-(-1)^1)*10^2) = 10 + 100.
G.f. = x + 10*x^2 + 11*x^3 + 100*x^4 + 101*x^5 + 110*x^6 + 111*x^7 + 1000*x^8 + ...
.
  000    The numbers < 2^n can be regarded as vectors with
  001    a fixed length n if padded with zeros on the left
  010    side. This represents the n-fold Cartesian product
  011    over the set {0, 1}. In the example on the left,
  100    n = 3. (See also the second Python program.)
  101    Binary vectors in this format can also be seen as a
  110    representation of the subsets of a set with n elements.
  111    - _Peter Luschny_, Jan 22 2024
		

References

  • John H. Conway and Richard K. Guy, The Book of Numbers, New York: Springer-Verlag, 1996. See p. 21.
  • Jan Gullberg, Mathematics from the Birth of Numbers, W. W. Norton & Co., NY & London, 1997, §2.8 Binary, Octal, Hexadecimal, p. 64.
  • Manfred R. Schroeder, "Fractals, Chaos, Power Laws", W. H. Freeman, 1991, p. 383.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

The basic sequences concerning the binary expansion of n are this one, A000120 (Hammingweight: sum of bits), A000788 (partial sums of A000120), A000069 (A000120 is odd), A001969 (A000120 is even), A023416 (number of bits 0), A059015 (partial sums). Bisections A099820 and A099821.
Cf. A028897 (convert binary to decimal).

Programs

  • Haskell
    a007088 0 = 0
    a007088 n = 10 * a007088 n' + m where (n',m) = divMod n 2
    -- Reinhard Zumkeller, Jan 10 2012
    
  • Maple
    A007088 := n-> convert(n, binary): seq(A007088(n), n=0..50); # R. J. Mathar, Aug 11 2009
  • Mathematica
    Table[ FromDigits[ IntegerDigits[n, 2]], {n, 0, 39}]
    Table[Sum[ (Floor[( Mod[f/2 ^n, 2])])*(10^n) , {n, 0, Floor[Log[2, f]]}], {f, 1, 100}] (* José de Jesús Camacho Medina, Jul 24 2014 *)
    FromDigits/@Tuples[{1,0},6]//Sort (* Harvey P. Dale, Aug 10 2017 *)
  • PARI
    {a(n) = subst( Pol( binary(n)), x, 10)}; /* Michael Somos, Jun 07 2002 */
    
  • PARI
    {a(n) = if( n<=0, 0, n%2 + 10*a(n\2))}; /* Michael Somos, Jun 07 2002 */
    
  • PARI
    a(n)=fromdigits(binary(n),10) \\ Charles R Greathouse IV, Apr 08 2015
    
  • Python
    def a(n): return int(bin(n)[2:])
    print([a(n) for n in range(40)]) # Michael S. Branicky, Jan 10 2021
    
  • Python
    from itertools import product
    n = 4
    for p in product([0, 1], repeat=n): print(''.join(str(x) for x in p))
    # Peter Luschny, Jan 22 2024

Formula

a(n) = Sum_{i=0..m} d(i)*10^i, where Sum_{i=0..m} d(i)*2^i is the base 2 representation of n.
a(n) = (1/2)*Sum_{i>=0} (1-(-1)^floor(n/2^i))*10^i. - Benoit Cloitre, Nov 20 2001
a(n) = A097256(n)/9.
a(2n) = 10*a(n), a(2n+1) = a(2n)+1.
G.f.: 1/(1-x) * Sum_{k>=0} 10^k * x^(2^k)/(1+x^(2^k)) - for sequence as decimal integers. - Franklin T. Adams-Watters, Jun 16 2006
a(A000290(n)) = A001737(n). - Reinhard Zumkeller, Apr 25 2009
a(n) = Sum_{k>=0} A030308(n,k)*10^k. - Philippe Deléham, Oct 19 2011
For n > 0: A054055(a(n)) = 1. - Reinhard Zumkeller, Apr 25 2012
a(n) = Sum_{k=0..floor(log_2(n))} floor((Mod(n/2^k, 2)))*(10^k). - José de Jesús Camacho Medina, Jul 24 2014

A055642 Number of digits in the decimal expansion of n.

Original entry on oeis.org

1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
Offset: 0

Views

Author

Henry Bottomley, Jun 06 2000

Keywords

Comments

From Hieronymus Fischer, Jun 08 2012: (Start)
For n > 0 the first differences of A117804.
The total number of digits necessary to write down all the numbers 0, 1, 2, ..., n is A117804(n+1). (End)
Here a(0) = 1, but a different common convention is to consider that the expansion of 0 in any base b > 0 has 0 terms and digits. - M. F. Hasler, Dec 07 2018

Examples

			Examples:
999: 1 + floor(log_10(999)) = 1 + floor(2.x) = 1 + 2 = 3 or
      ceiling(log_10(999+1)) = ceiling(log_10(1000)) = ceiling(3) = 3;
1000: 1 + floor(log_10(1000)) = 1 + floor(3) = 1 + 3 = 4 or
      ceiling(log_10(1000+1)) = ceiling(log_10(1001)) = ceiling(3.x) = 4;
1001: 1 + floor(log_10(1001)) = 1 + floor(3.x) = 1 + 3 = 4 or
      ceiling(log_10(1001+1)) = ceiling(log_10(1002)) = ceiling(3.x) = 4;
		

Crossrefs

Programs

  • Haskell
    a055642 :: Integer -> Int
    a055642 = length . show  -- Reinhard Zumkeller, Feb 19 2012, Apr 26 2011
    
  • Magma
    [ #Intseq(n): n in [0..105] ];   //  Bruno Berselli, Jun 30 2011
    (Common Lisp) (defun A055642 (n) (if (zerop n) 1 (floor (log n 10)))) ; James Spahlinger, Oct 13 2012
    
  • Maple
    A055642 := proc(n)
            max(1,ilog10(n)+1) ;
    end proc:  # R. J. Mathar, Nov 30 2011
  • Mathematica
    Join[{1}, Array[ Floor[ Log[10, 10# ]] &, 104]] (* Robert G. Wilson v, Jan 04 2006 *)
    Join[{1},Table[IntegerLength[n],{n,104}]]
    IntegerLength[Range[0,120]] (* Harvey P. Dale, Jul 02 2016 *)
  • PARI
    a(n)=#Str(n) \\ M. F. Hasler, Nov 17 2008
    
  • PARI
    A055642(n)=logint(n+!n,10)+1 \\ Increasingly faster than the above, for larger n. (About twice as fast for n ~ 10^7.) - M. F. Hasler, Dec 07 2018
    
  • Python
    def a(n): return len(str(n))
    print([a(n) for n in range(121)]) # Michael S. Branicky, May 10 2022
    
  • Python
    def A055642(n): # Faster than len(str(n)) from ~ 50 digits on
        L = math.log10(n or 1)
        if L.is_integer() and 10**int(L)>n: return int(L or 1)
        return int(L)+1  # M. F. Hasler, Apr 08 2024

Formula

a(A046760(n)) < A050252(A046760(n)); a(A046759(n)) > A050252(A046759(n)). - Reinhard Zumkeller, Jun 21 2011
a(n) = A196563(n) + A196564(n).
a(n) = 1 + floor(log_10(n)) = 1 + A004216(n) = ceiling(log_10(n+1)) = A004218(n+1), if n >= 1. - Daniel Forgues, Mar 27 2014
a(A046758(n)) = A050252(A046758(n)). - Reinhard Zumkeller, Jun 21 2011
a(n) = A117804(n+1) - A117804(n), n > 0. - Hieronymus Fischer, Jun 08 2012
G.f.: g(x) = 1 + (1/(1-x))*Sum_{j>=0} x^(10^j). - Hieronymus Fischer, Jun 08 2012
a(n) = A262190(n) for n < 100; a(A262198(n)) != A262190(A262198(n)). - Reinhard Zumkeller, Sep 14 2015

A000069 Odious numbers: numbers with an odd number of 1's in their binary expansion.

Original entry on oeis.org

1, 2, 4, 7, 8, 11, 13, 14, 16, 19, 21, 22, 25, 26, 28, 31, 32, 35, 37, 38, 41, 42, 44, 47, 49, 50, 52, 55, 56, 59, 61, 62, 64, 67, 69, 70, 73, 74, 76, 79, 81, 82, 84, 87, 88, 91, 93, 94, 97, 98, 100, 103, 104, 107, 109, 110, 112, 115, 117, 118, 121, 122, 124, 127, 128
Offset: 1

Views

Author

Keywords

Comments

This sequence and A001969 give the unique solution to the problem of splitting the nonnegative integers into two classes in such a way that sums of pairs of distinct elements from either class occur with the same multiplicities [Lambek and Moser]. Cf. A000028, A000379.
In French: les nombres impies.
Has asymptotic density 1/2, since exactly 2 of the 4 numbers 4k, 4k+1, 4k+2, 4k+3 have an even sum of bits, while the other 2 have an odd sum. - Jeffrey Shallit, Jun 04 2002
Nim-values for game of mock turtles played with n coins.
A115384(n) = number of odious numbers <= n; A000120(a(n)) = A132680(n). - Reinhard Zumkeller, Aug 26 2007
Indices of 1's in the Thue-Morse sequence A010060. - Tanya Khovanova, Dec 29 2008
For any positive integer m, the partition of the set of the first 2^m positive integers into evil ones E and odious ones O is a fair division for any polynomial sequence p(k) of degree less than m, that is, Sum_{k in E} p(k) = Sum_{k in O} p(k) holds for any polynomial p with deg(p) < m. - Pietro Majer, Mar 15 2009
For n>1 let b(n) = a(n-1). Then b(b(n)) = 2b(n). - Benoit Cloitre, Oct 07 2010
Lexicographically earliest sequence of distinct nonnegative integers with no term being the binary exclusive OR of any terms. The equivalent sequence for addition or for subtraction is A005408 (the odd numbers) and for multiplication is A026424. - Peter Munn, Jan 14 2018
Numbers of the form m XOR (2*m+1) for some m >= 0. - Rémy Sigrist, Apr 14 2022

Examples

			For k=2, x=0 and x=0.2 we respectively have 1^2 + 2^2 + 4^2 + 7^2 = 0^2 + 3^2 + 5^2 + 6^2 = 70;
(1.2)^2 + (2.2)^2 + (4.2)^2 + (7.2)^2 = (0.2)^2 + (3.2)^2 + (5.2)^2 + (6.2)^2 = 75.76;
for k=3, x=1.8, we have (2.8)^3 + (3.8)^3 + (5.8)^3 + (8.8)^3 + (9.8)^3 + (12.8)^3 + (14.8)^3 + (15.8)^3 = (1.8)^3 + (4.8)^3 + (6.8)^3 + (7.8)^3 + (10.8)^3 + (11.8)^3 + (13.8)^3 + (16.8)^3 = 11177.856. - _Vladimir Shevelev_, Jan 16 2012
		

References

  • E. R. Berlekamp, J. H. Conway and R. K. Guy, Winning Ways, Academic Press, NY, 2 vols., 1982, see p. 433.
  • J. Roberts, Lure of the Integers, Math. Assoc. America, 1992, p. 22.
  • Vladimir S. Shevelev, On some identities connected with the partition of the positive integers with respect to the Morse sequence, Izv. Vuzov of the North-Caucasus region, Nature sciences 4 (1997), 21-23 (in Russian).
  • N. J. A. Sloane, A handbook of Integer Sequences, Academic Press, 1973 (including this sequence).
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

The basic sequences concerning the binary expansion of n are A000120, A000788, A000069, A001969, A023416, A059015.
Complement of A001969 (the evil numbers). Cf. A133009.
a(n) = 2*n + 1 - A010060(n) = A001969(n) + (-1)^A010060(n).
First differences give A007413.
Note that A000079, A083420, A002042, A002089, A132679 are subsequences.
See A027697 for primes, also A230095.
Cf. A005408 (odd numbers), A006068, A026424.

Programs

  • Haskell
    a000069 n = a000069_list !! (n-1)
    a000069_list = [x | x <- [0..], odd $ a000120 x]
    -- Reinhard Zumkeller, Feb 01 2012
    
  • Magma
    [ n: n in [1..130] | IsOdd(&+Intseq(n, 2)) ]; // Klaus Brockhaus, Oct 07 2010
    
  • Maple
    s := proc(n) local i,j,k,b,sum,ans; ans := [ ]; j := 0; for i while jA000069 := n->t1[n]; # s(k) gives first k terms.
    is_A000069 := n -> type(add(i,i=convert(n,base,2)),odd):
    seq(`if`(is_A000069(i),i,NULL),i=0..40); # Peter Luschny, Feb 03 2011
  • Mathematica
    Select[Range[300], OddQ[DigitCount[ #, 2][[1]]] &] (* Stefan Steinerberger, Mar 31 2006 *)
    a[ n_] := If[ n < 1, 0, 2 n - 1 - Mod[ Total @ IntegerDigits[ n - 1, 2], 2]]; (* Michael Somos, Jun 01 2013 *)
  • PARI
    {a(n) = if( n<1, 0, 2*n - 1 - subst( Pol(binary( n-1)), x, 1) % 2)}; /* Michael Somos, Jun 01 2013 */
    
  • PARI
    {a(n) = if( n<2, n==1, if( n%2, a((n+1)/2) + n-1, -a(n/2) + 3*(n-1)))}; /* Michael Somos, Jun 01 2013 */
    
  • PARI
    a(n)=2*n-1-hammingweight(n-1)%2 \\ Charles R Greathouse IV, Mar 22 2013
    
  • Python
    [n for n in range(1, 201) if bin(n)[2:].count("1") % 2] # Indranil Ghosh, May 03 2017
    
  • Python
    def A000069(n): return ((m:=n-1)<<1)+(m.bit_count()&1^1) # Chai Wah Wu, Mar 03 2023

Formula

G.f.: 1 + Sum_{k>=0} (t*(2+2t+5t^2-t^4)/(1-t^2)^2) * Product_{j=0..k-1} (1-x^(2^j)), t=x^2^k. - Ralf Stephan, Mar 25 2004
a(n+1) = (1/2) * (4*n + 1 + (-1)^A000120(n)). - Ralf Stephan, Sep 14 2003
Numbers n such that A010060(n) = 1. - Benoit Cloitre, Nov 15 2003
a(2*n+1) + a(2*n) = A017101(n) = 8*n+3. a(2*n+1) - a(2*n) gives the Thue-Morse sequence (1, 3 version): 1, 3, 3, 1, 3, 1, 1, 3, 3, 1, 1, 3, 1, ... A001969(n) + A000069(n) = A016813(n) = 4*n+1. - Philippe Deléham, Feb 04 2004
(-1)^a(n) = 2*A010060(n)-1. - Benoit Cloitre, Mar 08 2004
a(1) = 1; for n > 1: a(2*n) = 6*n-3 -a(n), a(2*n+1) = a(n+1) + 2*n. - Corrected by Vladimir Shevelev, Sep 25 2011
For k >= 1 and for every real (or complex) x, we have Sum_{i=1..2^k} (a(i)+x)^s = Sum_{i=1..2^k} (A001969(i)+x)^s, s=0..k.
For x=0, s <= k-1, this is known as Prouhet theorem (see J.-P. Allouche and Jeffrey Shallit, The Ubiquitous Prouhet-Thue-Morse Sequence). - Vladimir Shevelev, Jan 16 2012
a(n+1) mod 2 = 1 - A010060(n) = A010059(n). - Robert G. Wilson v, Jan 18 2012
A005590(a(n)) > 0. - Reinhard Zumkeller, Apr 11 2012
A106400(a(n)) = -1. - Reinhard Zumkeller, Apr 29 2012
a(n+1) = A006068(n) XOR (2*A006068(n) + 1). - Rémy Sigrist, Apr 14 2022

A001969 Evil numbers: nonnegative integers with an even number of 1's in their binary expansion.

Original entry on oeis.org

0, 3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 23, 24, 27, 29, 30, 33, 34, 36, 39, 40, 43, 45, 46, 48, 51, 53, 54, 57, 58, 60, 63, 65, 66, 68, 71, 72, 75, 77, 78, 80, 83, 85, 86, 89, 90, 92, 95, 96, 99, 101, 102, 105, 106, 108, 111, 113, 114, 116, 119, 120, 123, 125, 126, 129
Offset: 1

Views

Author

Keywords

Comments

This sequence and A000069 give the unique solution to the problem of splitting the nonnegative integers into two classes in such a way that sums of pairs of distinct elements from either class occur with the same multiplicities [Lambek and Moser]. Cf. A000028, A000379.
In French: les nombres païens.
Theorem: First differences give A036585. (Observed by Franklin T. Adams-Watters.)
Proof from Max Alekseyev, Aug 30 2006 (edited by N. J. A. Sloane, Jan 05 2021): (Start)
Observe that if the last bit of a(n) is deleted, we get the nonnegative numbers 0, 1, 2, 3, ... in order.
The last bit in a(n+1) is 1 iff the number of bits in n is odd, that is, iff A010060(n+1) is 1.
So, taking into account the different offsets here and in A010060, we have a(n) = 2*(n-1) + A010060(n-1).
Therefore the first differences of the present sequence equal 2 + first differences of A010060, which equals A036585. QED (End)
Integers k such that A010060(k-1)=0. - Benoit Cloitre, Nov 15 2003
Indices of zeros in the Thue-Morse sequence A010060 shifted by 1. - Tanya Khovanova, Feb 13 2009
Conjecture, checked up to 10^6: a(n) is also the sequence of numbers k representable as k = ror(x) XOR rol(x) (for some integer x) where ror(x)=A038572(x) is x rotated one binary place to the right, rol(x)=A006257(x) is x rotated one binary place to the left, and XOR is the binary exclusive-or operator. - Alex Ratushnyak, May 14 2016
From Charlie Neder, Oct 07 2018: (Start)
Conjecture is true: ror(x) and rol(x) have an even number of 1 bits in total (= 2 * A000120(x)), and XOR preserves the parity of this total, so the resulting number must have an even number of 1 bits. An x can be constructed corresponding to a(n) like so:
If the number of bits in a(n) is even, add a leading 0 so a(n) is 2k+1 bits long.
Do an inverse shuffle on a(n), then "divide" by 11, rotate the result k bits to the right, and shuffle to get x. (End)
Numbers of the form m XOR (2*m) for some m >= 0. - Rémy Sigrist, Feb 07 2021
The terms "evil numbers" and "odious numbers" were coined by Richard K. Guy, c. 1976 (Haque and Shallit, 2016) and appeared in the book by Berlekamp et al. (Vol. 1, 1st ed., 1982). - Amiram Eldar, Jun 08 2021

References

  • Elwyn R. Berlekamp, John H. Conway, Richard K. Guy, Winning Ways for Your Mathematical Plays, Volume 1, 2nd ed., A K Peters, 2001, chapter 14, p. 110.
  • Hugh L. Montgomery, Ten Lectures on the Interface Between Analytic Number Theory and Harmonic Analysis, Amer. Math. Soc., 1996, p. 208.
  • Donald J. Newman, A Problem Seminar, Springer; see Problem #89.
  • Vladimir S. Shevelev, On some identities connected with the partition of the positive integers with respect to the Morse sequence, Izv. Vuzov of the North-Caucasus region, Nature sciences 4 (1997), 21-23 (Russian).
  • 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).

Crossrefs

Complement of A000069 (the odious numbers). Cf. A133009.
a(n)=2*n+A010060(n)=A000069(n)-(-1)^A010060(n). Cf. A018900.
The basic sequences concerning the binary expansion of n are A000120, A000788, A000069, A001969, A023416, A059015.
Cf. A036585 (differences), A010060, A006364.
For primes see A027699, also A130593.

Programs

  • Haskell
    a001969 n = a001969_list !! (n-1)
    a001969_list = [x | x <- [0..], even $ a000120 x]
    -- Reinhard Zumkeller, Feb 01 2012
    
  • Magma
    [ n : n in [0..129] | IsEven(&+Intseq(n,2)) ]; // Sergei Haller (sergei(AT)sergei-haller.de), Dec 21 2006
    
  • Maple
    s := proc(n) local i,j,ans; ans := [ ]; j := 0; for i from 0 while jA001969 := n->t1[n]; # s(k) gives first k terms.
    # Alternative:
    seq(`if`(add(k, k=convert(n,base,2))::even, n, NULL), n=0..129); # Peter Luschny, Jan 15 2021
    # alternative for use outside this sequence
    isA001969 := proc(n)
        add(d,d=convert(n,base,2)) ;
        type(%,'even') ;
    end proc:
    A001969 := proc(n)
        option remember ;
        local a;
        if n = 0 then
            1;
        else
            for a from procname(n-1)+1 do
                if isA001969(a) then
                    return a;
                end if;
            end do:
        end if;
    end proc:
    seq(A001969(n),n=1..200) ; # R. J. Mathar, Aug 07 2022
  • Mathematica
    Select[Range[0,300], EvenQ[DigitCount[ #, 2][[1]]] &]
    a[ n_] := If[ n < 1, 0, With[{m = n - 1}, 2 m + Mod[-Total@IntegerDigits[m, 2], 2]]]; (* Michael Somos, Jun 09 2019 *)
  • PARI
    a(n)=n-=1; 2*n+subst(Pol(binary(n)),x,1)%2
    
  • PARI
    a(n)=if(n<1,0,if(n%2==0,a(n/2)+n,-a((n-1)/2)+3*n))
    
  • PARI
    a(n)=2*(n-1)+hammingweight(n-1)%2 \\ Charles R Greathouse IV, Mar 22 2013
    
  • Python
    def ok(n): return bin(n)[2:].count('1') % 2 == 0
    print(list(filter(ok, range(130)))) # Michael S. Branicky, Jun 02 2021
    
  • Python
    from itertools import chain, count, islice
    def A001969_gen(): # generator of terms
        return chain((0,),chain.from_iterable((sorted(n^ n<<1 for n in range(2**l,2**(l+1))) for l in count(0))))
    A001969_list = list(islice(A001969_gen(),30)) # Chai Wah Wu, Jun 29 2022
    
  • Python
    def A001969(n): return ((m:=n-1).bit_count()&1)+(m<<1) # Chai Wah Wu, Mar 03 2023

Formula

a(n+1) - A001285(n) = 2n-1 has been verified for n <= 400. - John W. Layman, May 16 2003 [This can be directly verified by comparing Ralf Stephan's formulas for this sequence (see below) and for A001285. - Jianing Song, Nov 04 2024]
Note that 2n+1 is in the sequence iff 2n is not and so this sequence has asymptotic density 1/2. - Franklin T. Adams-Watters, Aug 23 2006
a(n) = (1/2) * (4n - 3 - (-1)^A000120(n-1)). - Ralf Stephan, Sep 14 2003
G.f.: Sum_{k>=0} (t(3+2t+3t^2)/(1-t^2)^2) * Product_{l=0..k-1} (1-x^(2^l)), where t = x^2^k. - Ralf Stephan, Mar 25 2004
a(2*n+1) + a(2*n) = A017101(n-1) = 8*n-5.
a(2*n) - a(2*n-1) gives the Thue-Morse sequence (3, 1 version): 3, 1, 1, 3, 1, 3, 3, 1, 1, 3, .... A001969(n) + A000069(n) = A016813(n-1) = 4*n-3. - Philippe Deléham, Feb 04 2004
a(1) = 0; for n > 1: a(n) = 3*n-3 - a(n/2) if n even, a(n) = a((n+1)/2)+n-1 if n odd.
Let b(n) = 1 if sum of digits of n is even, -1 if it is odd; then Shallit (1985) showed that Product_{n>=0} ((2n+1)/(2n+2))^b(n) = 1/sqrt(2).
a(n) = 2n - 2 + A010060(n-1). - Franklin T. Adams-Watters, Aug 28 2006
A005590(a(n-1)) <= 0. - Reinhard Zumkeller, Apr 11 2012
A106400(a(n-1)) = 1. - Reinhard Zumkeller, Apr 29 2012
a(n) = (a(n-1) + 2) XOR A010060(a(n-1) + 2). - Falk Hüffner, Jan 21 2022
a(n+1) = A006068(n) XOR (2*A006068(n)). - Rémy Sigrist, Apr 14 2022

Extensions

More terms from Robin Trew (trew(AT)hcs.harvard.edu)

A023416 Number of 0's in binary expansion of n.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Another version (A080791) has a(0) = 0.

Crossrefs

The basic sequences concerning the binary expansion of n are A000120, A000788, A000069, A001969, A023416, A059015, A070939, A083652. Partial sums see A059015.
With initial zero and shifted right, same as A080791.
Cf. A055641 (for base 10), A188859.

Programs

  • Haskell
    a023416 0 = 1
    a023416 1 = 0
    a023416 n = a023416 n' + 1 - m where (n', m) = divMod n 2
    a023416_list = 1 : c [0] where c (z:zs) = z : c (zs ++ [z+1,z])
    -- Reinhard Zumkeller, Feb 19 2012, Jun 16 2011, Mar 07 2011
    
  • Maple
    A023416 := proc(n)
        if n = 0 then
            1;
        else
            add(1-e,e=convert(n,base,2)) ;
        end if;
    end proc: # R. J. Mathar, Jul 21 2012
  • Mathematica
    Table[ Count[ IntegerDigits[n, 2], 0], {n, 0, 100} ]
    DigitCount[Range[0,110],2,0] (* Harvey P. Dale, Jan 10 2013 *)
  • PARI
    a(n)=if(n==0,1,n=binary(n); sum(i=1, #n, !n[i])) \\ Charles R Greathouse IV, Jun 10 2011
    
  • PARI
    a(n)=if(n==0,1,#binary(n)-hammingweight(n)) \\ Charles R Greathouse IV, Nov 20 2012
    
  • PARI
    a(n) = if(n == 0, 1, 1+logint(n,2) - hammingweight(n))  \\ Gheorghe Coserea, Sep 01 2015
    
  • Python
    def A023416(n): return n.bit_length()-n.bit_count() if n else 1 # Chai Wah Wu, Mar 13 2023

Formula

a(n) = 1, if n = 0; 0, if n = 1; a(n/2)+1 if n even; a((n-1)/2) if n odd.
a(n) = 1 - (n mod 2) + a(floor(n/2)). - Marc LeBrun, Jul 12 2001
G.f.: 1 + 1/(1-x) * Sum_{k>=0} x^(2^(k+1))/(1+x^2^k). - Ralf Stephan, Apr 15 2002
a(n) = A070939(n) - A000120(n).
a(n) = A008687(n+1) - 1.
a(n) = A000120(A035327(n)).
From Hieronymus Fischer, Jun 12 2012: (Start)
a(n) = m + 1 + Sum_{j=1..m+1} (floor(n/2^j) - floor(n/2^j + 1/2)), where m=floor(log_2(n)).
General formulas for the number of digits <= d in the base p representation n, where 0 <= d < p.
a(n) = m + 1 + Sum_{j=1..m+1} (floor(n/p^j) - floor(n/p^j + (p-d-1)/p)), where m=floor(log_p(n)).
G.f.: 1 + (1/(1-x))*Sum_{j>=0} ((1-x^(d*p^j))*x^p^j + (1-x^p^j)*x^p^(j+1)/(1-x^p^(j+1))). (End)
Product_{n>=1} ((2*n)/(2*n+1))^((-1)^a(n)) = sqrt(2)/2 (A010503) (see Allouche & Shallit link). - Michel Marcus, Aug 31 2014
Sum_{n>=1} a(n)/(n*(n+1)) = 2 - 2*log(2) (A188859) (Allouche and Shallit, 1990). - Amiram Eldar, Jun 01 2021

A000788 Total number of 1's in binary expansions of 0, ..., n.

Original entry on oeis.org

0, 1, 2, 4, 5, 7, 9, 12, 13, 15, 17, 20, 22, 25, 28, 32, 33, 35, 37, 40, 42, 45, 48, 52, 54, 57, 60, 64, 67, 71, 75, 80, 81, 83, 85, 88, 90, 93, 96, 100, 102, 105, 108, 112, 115, 119, 123, 128, 130, 133, 136, 140, 143, 147, 151, 156, 159, 163, 167, 172, 176, 181, 186
Offset: 0

Views

Author

Keywords

Comments

Partial sums of A000120.
The graph of this sequence is a version of the Takagi curve: see Lagarias (2012), Section 9, especially Theorem 9.1. - N. J. A. Sloane, Mar 12 2016
a(n-1) is the largest possible number of ordered pairs (a,b) such that a/b is a prime in a subset of the positive integers with n elements. - Yifan Xie, Feb 21 2025

References

  • J.-P. Allouche & J. Shallit, Automatic sequences, Cambridge University Press, 2003, p. 94
  • R. Bellman and H. N. Shapiro, On a problem in additive number theory, Annals Math., 49 (1948), 333-340. See Eq. 1.9. [From N. J. A. Sloane, Mar 12 2009]
  • L. E. Bush, An asymptotic formula for the average sums of the digits of integers, Amer. Math. Monthly, 47 (1940), pp. 154-156. [From the bibliography of Stolarsky, 1977]
  • P. Cheo and S. Yien, A problem on the k-adic representation of positive integers (Chinese; English summary), Acta Math. Sinica, 5 (1955), pp. 433-438. [From the bibliography of Stolarsky, 1977]
  • M. P. Drazin and J. S. Griffith, On the decimal representation of integers, Proc. Cambridge Philos. Soc., (4), 48 (1952), pp. 555-565. [From the bibliography of Stolarsky, 1977]
  • E. N. Gilbert, Games of identification or convergence, SIAM Review, 4 (1962), 16-24.
  • Grabner, P. J.; Kirschenhofer, P.; Prodinger, H.; Tichy, R. F.; On the moments of the sum-of-digits function. Applications of Fibonacci numbers, Vol. 5 (St. Andrews, 1992), 263-271, Kluwer Acad. Publ., Dordrecht, 1993.
  • R. L. Graham, On primitive graphs and optimal vertex assignments, pp. 170-186 of Internat. Conf. Combin. Math. (New York, 1970), Annals of the NY Academy of Sciences, Vol. 175, 1970.
  • E. Grosswald, Properties of some arithmetic functions, J. Math. Anal. Appl., 28 (1969), pp.405-430.
  • Donald E. Knuth, The Art of Computer Programming, volume 3 Sorting and Searching, section 5.3.4, subsection Bitonic sorting, with C'(p) = a(p-1).
  • Hiu-Fai Law, Spanning tree congestion of the hypercube, Discrete Math., 309 (2009), 6644-6648 (see p(m) on page 6647).
  • Z. Li and E. M. Reingold, Solution of a divide-and-conquer maximin recurrence, SIAM J. Comput., 18 (1989), 1188-1200.
  • B. Lindström, On a combinatorial problem in number theory, Canad. Math. Bull., 8 (1965), 477-490.
  • Mauclaire, J.-L.; Murata, Leo; On q-additive functions. I. Proc. Japan Acad. Ser. A Math. Sci. 59 (1983), no. 6, 274-276.
  • Mauclaire, J.-L.; Murata, Leo; On q-additive functions. II. Proc. Japan Acad. Ser. A Math. Sci. 59 (1983), no. 9, 441-444.
  • M. D. McIlroy, The number of 1's in binary integers: bounds and extremal properties, SIAM J. Comput., 3 (1974), 255-261.
  • L. Mirsky, A theorem on representations of integers in the scale of r, Scripta Math., 15 (1949), pp. 11-12.
  • I. Shiokawa, On a problem in additive number theory, Math. J. Okayama Univ., 16 (1974), pp.167-176. [From the bibliography of Stolarsky, 1977]
  • 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).
  • K. B. Stolarsky, Power and exponential sums of digital sums related to binomial coefficient parity, SIAM J. Appl. Math., 32 (1977), 717-730.
  • Trollope, J. R. An explicit expression for binary digital sums. Math. Mag. 41 1968 21-25.

Crossrefs

For number of 0's in binary expansion of 0, ..., n see A059015.
The basic sequences concerning the binary expansion of n are A000120, A000788, A000069, A001969, A023416, A059015, A070939, A083652.

Programs

  • Haskell
    a000788_list = scanl1 (+) A000120_list
    -- Walt Rorie-Baety, Jun 30 2012
    
  • Haskell
    {a000788 0 = 0; a00788 n = a000788 n2 + a000788 (n-n2-1) + (n-n2) where n2 = n `div` 2}
    -- Walt Rorie-Baety, Jul 15 2012
    
  • Maple
    a:= proc(n) option remember; `if`(n=0, 0, a(n-1)+add(i, i=Bits[Split](n))) end:
    seq(a(n), n=0..62);  # Alois P. Heinz, Nov 11 2024
  • Mathematica
    a[n_] := Count[ Table[ IntegerDigits[k, 2], {k, 0, n}], 1, 2]; Table[a[n], {n, 0, 62}] (* Jean-François Alcover, Dec 16 2011 *)
    Table[Plus@@Flatten[IntegerDigits[Range[n], 2]], {n, 0, 62}] (* Alonso del Arte, Dec 16 2011 *)
    Accumulate[DigitCount[Range[0,70],2,1]] (* Harvey P. Dale, Jun 08 2013 *)
  • PARI
    A000788(n)={ n<3 && return(n); if( bittest(n,0) \\
    , n+1 == 1<A000788(n>>1)*2+n>>1+1 \\
    , n == 1<A000788(n>>=1)+A000788(n-1)+n )} \\ M. F. Hasler, Nov 22 2009
    
  • PARI
    a(n)=sum(k=1,n,hammingweight(k)) \\ Charles R Greathouse IV, Oct 04 2013
    
  • PARI
    a(n) = if (n==0, 0, m = logint(n, 2); r = n % 2^m; m*2^(m-1) + r + 1 + a(r)); \\ Michel Marcus, Mar 27 2018
    
  • PARI
    a(n)={n++; my(t, i, s); c=n; while(c!=0, i++; c\=2); for(j=1, i, d=(n\2^(i-j))%2; t+=(2^(i-j)*(s*d+d*(i-j)/2)); s+=d); t} \\ David A. Corneth, Nov 26 2024
    (C++) /* See David W. Wilson link. */
    
  • Python
    def A000788(n): return sum(i.bit_count() for i in range(1,n+1)) # Chai Wah Wu, Mar 01 2023
    
  • Python
    def A000788(n): return (n+1)*n.bit_count()+(sum((m:=1<>j)-(r if n<<1>=m*(r:=k<<1|1) else 0)) for j in range(1,n.bit_length()+1))>>1) # Chai Wah Wu, Nov 11 2024

Formula

McIlroy (1974) gives bounds and recurrences. - N. J. A. Sloane, Mar 24 2014
Stolarsky (1977) studies the asymptotics, and gives at least nine references to earlier work on the problem. I have added all the references that were not here already. - N. J. A. Sloane, Apr 06 2014
a(n) = Sum_{k=1..n} A000120(k). - Benoit Cloitre, Dec 19 2002
a(0) = 0, a(2n) = a(n)+a(n-1)+n, a(2n+1) = 2a(n)+n+1. - Ralf Stephan, Sep 13 2003
a(n) = n*log_2(n)/2 + O(n); a(2^n)=n*2^(n-1)+1. - Benoit Cloitre, Sep 25 2003 (The first result is due to Bellman and Shapiro, - N. J. A. Sloane, Mar 24 2014)
a(n) = n*log_2(n)/2+n*F(log_2(n)) where F is a nowhere differentiable continuous function of period 1 (see Allouche & Shallit). - Benoit Cloitre, Jun 08 2004
G.f.: (1/(1-x)^2) * Sum_{k>=0} x^2^k/(1+x^2^k). - Ralf Stephan, Apr 19 2003
a(2^n-1) = A001787(n) = n*2^(n-1). - M. F. Hasler, Nov 22 2009
a(4^n-2) = n(4^n-2).
For real n, let f(n) = [n]/2 if [n] even, n-[n+1]/2 otherwise. Then a(n) = Sum_{k>=0} 2^k*f((n+1)/2^k).
a(A000225(n)) = A173921(A000225(n)) = A001787(n); a(A000079(n)) = A005183(n). - Reinhard Zumkeller, Mar 04 2010
From Hieronymus Fischer, Jun 10 2012: (Start)
a(n) = (1/2)*Sum_{j=1..m+1} (floor(n/2^j + 1/2)*(2n + 2 - floor(n/2^j + 1/2))*2^j - floor(n/2^j)*(2n + 2 - (1 + floor(n/2^j)) * 2^j)), where m=floor(log_2(n)).
a(n) = (n+1)*A000120(n) - 2^(m-1) + 1/4 + (1/2)*Sum_{j=1..m+1} ((floor(n/2^j) + 1/2)^2 - floor(n/2^j + 1/2)^2)*2^j, where m=floor(log_2(n)).
a(2^m-1) = m*2^(m-1).
(This is the total number of '1' digits occurring in all the numbers with <= m bits.)
Generic formulas for the number of digits >= d in the base p representations of all integers from 0 to n, where 1<= d < p.
a(n) = (1/2)*Sum_{j=1..m+1} (floor(n/p^j + (p-d)/p)*(2n + 2 + ((p-2*d)/p - floor(n/p^j + (p-d)/p))*p^j) - floor(n/p^j)*(2n + 2 - (1+floor(n/p^j)) * p^j)), where m=floor(log_p(n)).
a(n) = (n+1)*F(n,p,d) + (1/2)*Sum_{j=1..m+1} ((((p-2*d)/p)*floor(n/p^j+(p-d)/p) + floor(n/p^j))*p^j - (floor(n/p^j+(p-d)/p)^2 - floor(n/p^j)^2)*p^j), where m=floor(log_p(n)) and F(n,p,d) = number of digits >= d in the base p representation of n.
a(p^m-1) = (p-d)*m*p^(m-1).
(This is the total number of digits >= d occurring in all the numbers with <= m digits in base p representation.)
G.f.: g(x) = (1/(1-x)^2)*Sum_{j>=0} (x^(d*p^j) - x^(p*p^j))/(1-x^(p*p^j)). (End)
a(n) = Sum_{k=1..n} A000120(A240857(n,k)). - Reinhard Zumkeller, Apr 14 2014
For n > 0, if n is written as 2^m + r with 0 <= r < 2^m, then a(n) = m*2^(m-1) + r + 1 + a(r). - Shreevatsa R, Mar 20 2018
a(n) = n*(n+1)/2 + Sum_{k=1..floor(n/2)} ((2k-1)((g(n,k)-1)*2^(g(n,k) + 1) + 2) - (n+1)*(g(n,k)+1)*g(n,k)/2), where g(n,k) = floor(log_2(n/(2k-1))). - Fabio Visonà, Mar 17 2020
From Jeffrey Shallit, Aug 07 2021: (Start)
A 2-regular sequence, satisfying the identities
a(4n+1) = -a(2n) + a(2n+1) + a(4n)
a(4n+2) = -2a(2n) + 2a(2n+1) + a(4n)
a(4n+3) = -4a(n) + 4a(2n+1)
a(8n) = 4a(n) - 8a(2n) + 5a(4n)
a(8n+4) = -9a(2n) + 5a(2n+1) + 4a(4n)
for n>=0. (End)
a(n) = Sum_{k=0..floor(log_2(n+1))} k * A360189(n,k). - Alois P. Heinz, Mar 06 2023

Extensions

More terms from Larry Reeves (larryr(AT)acm.org), Jan 15 2001

A055641 Number of zero digits in n.

Original entry on oeis.org

1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 1, 1, 1
Offset: 0

Views

Author

Henry Bottomley, Jun 06 2000

Keywords

Examples

			a(99) = 0 because the digits of 99 are 9 and 9, a(100) = 2 because the digits of 100 are 1, 0 and 0 and there are two 0's.
		

Crossrefs

Programs

  • Haskell
    a055641 n | n < 10    = 0 ^ n
              | otherwise = a055641 n' + 0 ^ d where (n',d) = divMod n 10
    -- Reinhard Zumkeller, Apr 30 2013
    
  • Mathematica
    Array[Last@ DigitCount@ # &, 105] (* Michael De Vlieger, Jul 02 2015 *)
  • PARI
    a(n)=if(n,n=digits(n); sum(i=2,#n,n[i]==0), 1) \\ Charles R Greathouse IV, Sep 13 2015
    
  • PARI
    A055641(n)=#select(d->!d,digits(n))+!n \\ M. F. Hasler, Jun 22 2018
    
  • Python
    def a(n): return str(n).count("0")
    print([a(n) for n in range(106)]) # Michael S. Branicky, May 26 2022

Formula

From Hieronymus Fischer, Jun 06 2012: (Start)
a(n) = m + 1 - A055640(n) = Sum_{j=1..m+1} (1 + floor(n/10^j) - floor(n/10^j+0.9)), where m = floor(log_10(n)).
G.f.: g(x) = 1 + (1/(1-x))*Sum_{j>=0} (x^(10*10^j) - x^(11*10^j))/(1-x^10^(j+1)). (End)
a(n) = if n<10 then A000007(n) else a(A059995(n)) + A000007(A010879(n)). - Reinhard Zumkeller, Apr 30 2013, corrected by M. F. Hasler, Jun 22 2018

A055640 Number of nonzero digits in decimal expansion of n.

Original entry on oeis.org

0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2
Offset: 0

Views

Author

Henry Bottomley, Jun 06 2000

Keywords

Comments

Comment from Antti Karttunen, Sep 05 2004: (Start)
Also number of characters needed to write the number n in classical Greek alphabetic system, up to n=999. The Greek alphabetic system assigned values to the letters as follows:
alpha = 1, beta = 2, gamma = 3, delta = 4, epsilon = 5, digamma = 6, zeta = 7, eta = 8, theta = 9, iota = 10, kappa = 20, lambda = 30, mu = 40, nu = 50, xi = 60, omicron = 70, pi = 80, koppa = 90, rho = 100, sigma = 200, tau = 300, upsilon = 400, phi = 500, chi = 600, psi = 700, omega = 800, sampi = 900. (End)
For partial sums see A102685. - Hieronymus Fischer, Jun 06 2012

Examples

			129 is written as rho kappa theta in the old Greek system.
		

References

  • L. Threatte, The Greek Alphabet, in The World's Writing Systems, edited by Peter T. Daniels and William Bright, Oxford Univ. Press, 1996, p. 278.

Crossrefs

Differs from A098378 for the first time at position n=200 with a(200)=1, as only one nonzero Arabic digit (and only one Greek letter) is needed for two hundred, while A098378(200)=2 as two characters are needed in the Ethiopic system.

Programs

Formula

From Hieronymus Fischer, Jun 06 2012: (Start)
a(n) = Sum_{j=1..m+1} (floor(n/10^j+0.9) - floor(n/10^j)), where m = floor(log_10(n)).
a(n) = m + 1 - A055641(n).
G.f.: (1/(1-x))*Sum_{j>=0} (x^10^j - x^(10*10^j))/(1-x^10^(j+1)). (End)
a(n) = A055642(n) - A055641(n).
Showing 1-10 of 47 results. Next