|
|
A233904
|
|
a(2n) = a(n) - n, a(2n+1) = a(n) + n, with a(0)=0.
|
|
1
|
|
|
0, 0, -1, 1, -3, 1, -2, 4, -7, 1, -4, 6, -8, 4, -3, 11, -15, 1, -8, 10, -14, 6, -5, 17, -20, 4, -9, 17, -17, 11, -4, 26, -31, 1, -16, 18, -26, 10, -9, 29, -34, 6, -15, 27, -27, 17, -6, 40, -44, 4
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
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
|
a(n) = sum(k=0..floor(log(n)/log(2)), (2*bittest(n,k)-1) * floor(n/2^(k+1)) ) = sum(k=0..A000523(n), (2*A030308(n,k+1)-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).
|
|
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)))))
|
|
CROSSREFS
|
|
|
KEYWORD
|
sign
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|