OFFSET
0,3
REFERENCES
D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
Wikipedia, Balanced Ternary
FORMULA
For n>0: a(n) = ceiling(log(2*n+1)/log(3)).
EXAMPLE
100=1*3^4+1*3^3-1*3^2+0*3^1+1*3^0: a(100)=|++-0+|=5;
200=1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0: a(200)=|+-+++-|=6;
300=1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0: a(300)=|++-0+0|=6.
PROG
(Python)
def a(n):
if n==0: return 1
s=0
x=0
while n>0:
x=n%3
n=n//3
if x==2:
x=-1
n+=1
s+=1
return s
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Reinhard Zumkeller, Oct 19 2007
STATUS
approved