OFFSET
0,5
COMMENTS
For every zero bit in the binary representation of n, add the number represented by the substring left of it.
LINKS
FORMULA
EXAMPLE
17 is 10001 in binary, so we add 1, 10=2, and 100=4 so a(17)=7.
27 is 11011 in binary, so we add 11=3, so a(27)=3.
PROG
(PARI) a(n)=sum(k=0, floor(log(n)/log(2)), (1-bittest(n, k))*floor(n/2^(k+1)))
(PARI) a(n)=b=binary(n); sum(k=1, #b, (!b[k])*sum(i=1, k-1, b[i]*2^(k-1-i)))
(PARI) a(n)=if(n<1, 0, if(n%2, a(n\2), a(n/2)+n/2))
(Scheme, with memoizing definec-macro from Antti Karttunen's IntSeq-library)
(definec (A233931 n) (cond ((zero? n) n) ((even? n) (+ (A233931 (/ n 2)) (/ n 2))) (else (A233931 (/ (- n 1) 2)))))
;; Antti Karttunen, Dec 21 2013
CROSSREFS
KEYWORD
nonn
AUTHOR
Ralf Stephan, Dec 18 2013
STATUS
approved