OFFSET
1,2
LINKS
FORMULA
MATHEMATICA
w[n_] := Plus@@IntegerDigits[n, 2]; p[n_] := Plus@@MapThread[Binomial, {Flatten[Position[Reverse[IntegerDigits[n, 2]], 1]]-1, Range[w[n]]}]; a[n_] := Binomial[w[n]+p[n], 2]+p[n]+1
PROG
(Perl)
foreach(1..10_000){$i=eval join "+", split //, sprintf "%b", $_; $j=$r[$i]++; print "$_ ", $j+1+($i+$j)*($i+$j-1)/2, "\n"} # Ivan Neretin, Mar 02 2016
(PARI) a(n)=my(w=hammingweight(n), p=sum(i=1, n-1, hammingweight(i)==w)); binomial(w+p, 2) + p + 1 \\ Jianing Song, Aug 06 2022
(Python)
from math import comb
def A067587(n):
c, k = 0, 0
for i, j in enumerate(bin(n)[-1:1:-1]):
if j == '1':
k += 1
c += comb(i, k)
return comb(n.bit_count()+c, 2)+c+1 # Chai Wah Wu, Mar 02 2023
CROSSREFS
KEYWORD
AUTHOR
Jared Ricks (jaredricks(AT)yahoo.com), Jan 31 2002
EXTENSIONS
Edited by Dean Hickerson, Feb 16 2002
Offset changed to 1 by Ivan Neretin, Mar 02 2016
STATUS
approved