A273004 Sum of coefficients in the hereditary representation of n in base 2.
0, 1, 2, 3, 3, 4, 5, 6, 4, 5, 6, 7, 7, 8, 9, 10, 4, 5, 6, 7, 7, 8, 9, 10, 8, 9, 10, 11, 11, 12, 13, 14, 5, 6, 7, 8, 8, 9, 10, 11, 9, 10, 11, 12, 12, 13, 14, 15, 9, 10, 11, 12, 12, 13, 14, 15, 13, 14, 15, 16, 16, 17, 18, 19, 6, 7, 8, 9, 9, 10, 11, 12, 10, 11, 12, 13, 13, 14, 15, 16, 10, 11, 12, 13, 13, 14, 15, 16, 14, 15, 16, 17, 17, 18, 19, 20, 11, 12, 13, 14, 14
Offset: 0
Examples
266 = 1*2^1 + 1*2^(1+1*2^1) + 1*2^(1*2^(1+1*2^1)) which can be represented as [[1, [1]], [1, [1, [1, [1]]]], [1, [[1, [1, [1, [1]]]]]]], and there are 11 "1"s, therefore a(266) = 11.
Links
- Andrei Zabolotskii, Table of n, a(n) for n = 0..8191
- Eric Weisstein's World of Mathematics, Hereditary Representation.
Programs
-
Mathematica
a[n_] := a[n] = Total[1 + a /@ Log2[DeleteCases[NumberExpand[n, 2], 0]]]; (* Vladimir Reshetnikov, Dec 21 2023 *)
-
PARI
(hr(n,b=2)=if(1<#n=digits(n,b),my(v=if(n[#n],[n[#n]],[]));forstep(i=#n-1,1,-1,n[i]&&v=concat(v,[[n[i],hr(#n-i,b)]]));v,n));(cc(v)=if(type(v)=="t_VEC",sum(i=1,#v,cc(v[i])),v)); a(n)=cc(hr(n))
-
Python
def A273004(n): s=format(n,'b')[::-1] return sum(1+A273004(i) for i in range(len(s)) if s[i]=='1') # Pontus von Brömssen, Sep 17 2020
Formula
If n = Sum_{j=1..k} 2^e_j where 0 <= e_1 < ... < e_k, then a(n) = k + Sum_{j=1..k} a(e_j). - Pontus von Brömssen, Sep 17 2020
Comments