OFFSET
0,3
COMMENTS
LINKS
EXAMPLE
For n = 42: the balanced ternary expansion of 42 is "1TTT0" (where T denotes -1), and T_42 is as follows:
T
0 1
1 T 0
0 T T 1
1 T T T 0
So the balanced ternary expansion of a(42) is "1010T", and a(42) = 89.
PROG
(PARI) a(n) = { my (b = [], d); while (n, b = concat(d = Mod(n, 3), b); n = (n-centerlift(d)) / 3; ); my (t = vector(#b)); for (i = 1, #t, t[i] = centerlift(b[1]); b = -vector(#b-1, j, b[j]+b[j+1]); ); fromdigits(t, 3); }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Mar 30 2024
STATUS
approved