OFFSET
0,3
LINKS
FORMULA
a(0) = 0, and provided that d=1, 2 or 3, then a((d*(4^i))+r) = (((2+(i mod 2))^d mod 5)-1) * [either A024036(i) - a(r), if d is 3, and A057300(a(r)) in other cases].
From Antti Karttunen, Apr 14 2018: (Start)
(End)
PROG
(MIT Scheme:)
(define (A163356 n) (if (zero? n) n (let* ((i (floor->exact (/ (A000523 n) 2))) (d (modulo (floor->exact (/ n (expt 4 i))) 4)) (r (modulo n (expt 4 i)))) (+ (* (-1+ (modulo (expt (+ 2 (modulo i 2)) d) 5)) (expt 4 i)) (cond ((= 3 d) (- (expt 4 i) 1 (A163356 r))) (else (A057300 (A163356 r))))))))
(Another, iterative version): (define (A163356v2 n) (let loop ((z 0) (n n) (i 0)) (let ((dd (modulo n 4))) (cond ((zero? n) z) ((= 0 dd) (loop z (floor->exact (/ n 4)) (+ i 2))) ((= 2 dd) (loop (+ (* 3 (expt 2 i)) (A057300 z)) (floor->exact (/ n 4)) (+ i 2))) ((= 1 dd) (loop (+ (expt 2 (+ i (floor->exact (/ (modulo i 4) 2)))) (A057300 z)) (floor->exact (/ n 4)) (+ i 2))) (else (loop (+ (expt 2 (+ i (- 1 (floor->exact (/ (modulo i 4) 2))))) (- (expt 2 i) z 1)) (floor->exact (/ n 4)) (+ i 2)))))))
(PARI)
A057300(n) = { my(t=1, s=0); while(n>0, if(1==(n%4), n++, if(2==(n%4), n--)); s += (n%4)*t; n >>= 2; t <<= 2); (s); };
A163356(n) = if(!n, n, my(i = (#binary(n)-1)\2, f = 4^i, d = (n\f)%4, r = (n%f)); (((((2+(i%2))^d)%5)-1)*f) + if(3==d, f-1-A163356(r), A057300(A163356(r)))); \\ Antti Karttunen, Apr 14 2018
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jul 29 2009
EXTENSIONS
Links to further derived sequences and a nicer Scheme function & formula added by Antti Karttunen, Sep 21 2009
STATUS
approved