A008687 Number of 1's in 2's complement representation of -n.
0, 1, 1, 2, 1, 3, 2, 2, 1, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 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, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3
Offset: 0
Examples
Using the above recursion for a(n); n >= 2, we have: S(0) = {1} so a(2) = 1; S(1) = {2,1} so a(3,4) = 2,1; S(2) = {3,2,2,1}, so a(5,6,7,8) = 3,2,2,1; As irregular table the sequence for n >= 2 begins: 1; 2,1; 3,2,2,1; 4,3,3,2,3,2,2,1; 5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1; 6,5,5,4,5,4,4,3,5,4,3,3,4,3,3,2,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1; and so on (the k-th row contains 2^k terms; k>=0). - _David James Sycamore_, Jul 15 2024
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- Michael Gilleland, Some Self-Similar Integer Sequences
- Wikipedia, Two's complement
Crossrefs
Programs
-
Haskell
a008687 n = a008687_list !! n a008687_list = 0 : 1 : c [1] where c (e:es) = e : c (es ++ [e+1,e]) -- Reinhard Zumkeller, Mar 07 2011
-
Mathematica
a[0] = 0; a[1] = 1; a[n_] := a[n] = Mod[n,2] + a[Mod[n,2] + Floor[n/2]]; Array[a, 96, 0] (* Jean-François Alcover, Aug 12 2017, after Reinhard Zumkeller *)
-
PARI
a(n) = if(n<2,n, n--; logint(n,2) - hammingweight(n) + 2); \\ Kevin Ryde, Apr 14 2021
Formula
a(n) = A023416(n-1) + 1.
a(n) = if n<=1 then n else (n mod 2) + a((n mod 2) + floor(n/2)). - Reinhard Zumkeller, Feb 05 2007
a(n) = if n<2 then n else a(ceiling(n/2)) + n mod 2. - Reinhard Zumkeller, Jul 25 2006
Min{m: a(m)=n} = if n>0 then A083318(n-1) else 0. - Reinhard Zumkeller, Jul 25 2006
Comments