OFFSET
0,3
LINKS
FORMULA
PROG
(Scheme, with memoizing macro definec)
(definec (A254104 n) (cond ((< n 1) n) ((= 2 (modulo n 3)) (* 2 (A254104 (/ (+ n 1) 3)))) (else (+ 1 (* 2 (A254104 (+ -1 (inv_for_A032766 n))))))))
(define (inv_for_A032766 n) (+ (* 2 (floor->exact (/ n 3))) (modulo n 3)))
(Python)
def a(n):
if n==0: return 0
if n%3==0: return 1 + 2*a(2*n//3 - 1)
elif n%3==1: return 1 + 2*a(2*(n - 1)//3)
else: return 2*a((n - 2)//3 + 1)
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jan 25 2015
STATUS
approved