OFFSET
1,2
LINKS
FORMULA
a(a(n)) = n, self-inverse permutation of natural numbers.
a(n) = n iff n = 2^k - 1, k>0.
a(2n+1) = 2a(n)+1, a(4n+2) = 8n+4, a(4n) = 2n(4-3*A035263(n)). - Ralf Stephan, Oct 09 2003
EXAMPLE
n = 43 in binary 101011: insert a 0 in the rightmost block of zeros consisting of one (odd!) 0: 1010011 -> 83 = a(43).
n = 41 in binary 101001: delete a 0 from the rightmost block of zeros consisting of two (even!) 0's: 10101 -> 21 = a(41).
MATHEMATICA
a[n_] := a[n] = If[OddQ[n], 2*a[(n - 1)/2] + 1, If[EvenQ[IntegerExponent[n, 2]], n/2, 2*n]]; Array[a, 100] (* Amiram Eldar, Jul 22 2023 *)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Reinhard Zumkeller, May 27 2003
STATUS
approved