OFFSET
0,5
COMMENTS
For every bit in the binary representation of n, if it is one then add the number represented by the substring left of it, and if it is zero subtract that.
LINKS
FORMULA
EXAMPLE
27 is 11011 in binary, so we add 1, subtract 11=3, add 110=6, and add 1101=13, so a(27)=17.
PROG
(PARI) a(n)=sum(k=0, floor(log(n)/log(2)), (2*bittest(n, k)-1)*floor(n/2^(k+1)))
(PARI) a(n)=if(n<1, 0, if(n%2, a(n\2)+n\2, a(n/2)-n/2))
(Scheme, with memoizing definec-macro from Antti Karttunen's IntSeq-library)
(definec (A233904 n) (cond ((zero? n) n) ((even? n) (- (A233904 (/ n 2)) (/ n 2))) (else (+ (A233904 (/ (- n 1) 2)) (/ (- n 1) 2)))))
;; Antti Karttunen, Dec 21 2013
CROSSREFS
KEYWORD
sign
AUTHOR
Ralf Stephan, Dec 17 2013
STATUS
approved