OFFSET
0,2
COMMENTS
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..32767
PROG
(Scheme) (define (A209642 n) (let loop ((n n) (s 0) (i 1)) (cond ((zero? n) s) ((even? n) (loop (/ n 2) (+ (* 4 s) 1) (* i 4))) (else (loop (/ (- n 1) 2) (* 2 (+ s i)) (* i 4))))))
(Python)
def a(n):
s=0
i=1
while n!=0:
if n%2==0:
n//=2
s=4*s + 1
else:
n=(n - 1)//2
s=(s + i)*2
i*=4
return s
print([a(n) for n in range(101)]) # Indranil Ghosh, May 25 2017, translated from Antti Karttunen's SCHEME code
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Antti Karttunen, Mar 11 2012
STATUS
approved