OFFSET
0,3
COMMENTS
Notation: (3)[n](2).
Fixed point of the morphism 0->0,1,2; 1->2,3,4; 2->4,5,6; ...; n->2n,2n+1,2n+2. - Philippe Deléham, Oct 22 2011
LINKS
Harry J. Smith, Table of n, a(n) for n = 0..1000
FORMULA
a(0)=0, a(3n)=2*a(n), a(3n+1)=2*a(n)+1, a(3n+2)=2*a(n)+2. - Benoit Cloitre, Dec 21 2002
a(n) = 2*a(floor(n/3))+n-3*floor(n/3). - Benoit Cloitre, Apr 27 2003
a(n) = Sum_{k>=0} A030341(n,k)*2^k. - Philippe Deléham, Oct 22 2011
EXAMPLE
15 = 120 -> 1(4)+2(2)+0(1) = 8 = a(15).
MATHEMATICA
t = Table[FromDigits[RealDigits[n, 3], 2], {n, 0, 100}]
(* Clark Kimberling, Aug 02 2012 *)
PROG
(PARI) a(n)=if(n<1, 0, if(n%3, a(n-1)+1, 2*a(n/3)))
(PARI) a(n)=if(n<1, 0, 2*a(floor(n/3))+n-3*floor(n/3))
(PARI) Rebase(x, b, c)= { local(d, e=0, f=1); while (x>0, d=x-b*(x\b); x\=b; e+=d*f; f*=c); return(e) } { for (n=0, 1000, write("b065361.txt", n, " ", Rebase(n, 3, 2)) ) } \\ Harry J. Smith, Oct 17 2009
(Julia)
function a(n)
m, r, b = n, 0, 1
while m > 0
m, q = divrem(m, 3)
r += b * q
b *= 2
end
r end; [a(n) for n in 0:76] |> println # Peter Luschny, Jan 03 2021
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Marc LeBrun, Oct 31 2001
STATUS
approved