login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A233904 a(2n) = a(n) - n, a(2n+1) = a(n) + n, with a(0)=0. 1

%I #16 Dec 22 2013 02:01:14

%S 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,

%T 4,-9,17,-17,11,-4,26,-31,1,-16,18,-26,10,-9,29,-34,6,-15,27,-27,17,

%U -6,40,-44,4

%N a(2n) = a(n) - n, a(2n+1) = a(n) + n, with a(0)=0.

%C 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.

%H Antti Karttunen, <a href="/A233904/b233904.txt">Table of n, a(n) for n = 0..8192</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F 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).

%F a(n) = A233905(n) - A233931(n).

%e 27 is 11011 in binary, so we add 1, subtract 11=3, add 110=6, and add 1101=13, so a(27)=17.

%o (PARI) a(n)=sum(k=0,floor(log(n)/log(2)),(2*bittest(n,k)-1)*floor(n/2^(k+1)))

%o (PARI) a(n)=if(n<1,0,if(n%2,a(n\2)+n\2,a(n/2)-n/2))

%o (Scheme, with memoizing definec-macro from _Antti Karttunen_'s IntSeq-library)

%o (definec (A233904 n) (cond ((zero? n) n) ((even? n) (- (A233904 (/ n 2)) (/ n 2))) (else (+ (A233904 (/ (- n 1) 2)) (/ (- n 1) 2)))))

%o ;; _Antti Karttunen_, Dec 21 2013

%K sign

%O 0,5

%A _Ralf Stephan_, Dec 17 2013

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 01:35 EDT 2024. Contains 371964 sequences. (Running on oeis4.)