OFFSET
1,1
REFERENCES
D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175
LINKS
Indranil Ghosh, Table of n, a(n) for n = 1..6561
Ken Levasseur, The Balanced Ternary Number System
FORMULA
a(1) = 2, a(3n) = 3a(n), a(3n+1) = 3a(n)+2, a(3n-1) = 3a(n)+1.
EXAMPLE
-7 in balanced ternary is (-1)1(-1), changing to 212 ternary is 23, so a(7)=23.
PROG
(Python)
def a(n):
if n==1: return 2
if n%3==0: return 3*a(n//3)
elif n%3==1: return 3*a((n - 1)//3) + 2
else: return 3*a((n + 1)//3) + 1
print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 06 2017
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Franklin T. Adams-Watters, Apr 05 2006
STATUS
approved