login
A233931
a(2n) = a(n) + n, a(2n+1) = a(n), with a(0)=0.
3
0, 0, 1, 0, 3, 1, 3, 0, 7, 3, 6, 1, 9, 3, 7, 0, 15, 7, 12, 3, 16, 6, 12, 1, 21, 9, 16, 3, 21, 7, 15, 0, 31, 15, 24, 7, 30, 12, 22, 3, 36, 16, 27, 6, 34, 12, 24, 1, 45, 21, 34, 9, 42, 16, 30, 3, 49, 21, 36, 7, 45, 15, 31, 0, 63, 31, 48, 15, 58, 24, 42, 7, 66, 30, 49, 12, 60, 22, 42, 3, 76, 36, 57
OFFSET
0,5
COMMENTS
For every zero bit in the binary representation of n, add the number represented by the substring left of it.
FORMULA
a(n) = Sum_{k=0..floor(log_2(n))} (1-bittest(n,k)) * floor(n/2^(k+1)) = Sum_{k=0..A000523(n)} (1-A030308(n,k+1)) * floor(n/2^(k+1)), with bittest(n,k)=0 or 1 according to the k-th bit of n (the zeroth bit the least significant).
a(n) = A011371(n) - A233905(n).
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)=if(n<1, 0, sum(k=0, logint(n, 2), (1-bittest(n, k))*floor(n/2^(k+1))))
(PARI) a(n)=my(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
Sequence in context: A174233 A079530 A020815 * A280725 A243328 A243332
KEYWORD
nonn,easy
AUTHOR
Ralf Stephan, Dec 18 2013
STATUS
approved