cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A134021 Length of n in balanced ternary representation.

This page as a plain text file.
%I A134021 #28 Apr 03 2025 01:34:21
%S A134021 1,1,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
%T A134021 4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
%U A134021 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
%N A134021 Length of n in balanced ternary representation.
%C A134021 Shifted variant of A064099.
%D A134021 Donald E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175.
%H A134021 Reinhard Zumkeller, <a href="/A134021/b134021.txt">Table of n, a(n) for n = 0..10000</a>
%H A134021 Wikipedia, <a href="http://en.wikipedia.org/wiki/Balanced_ternary">Balanced Ternary</a>.
%F A134021 For n > 0: a(n) = ceiling(log(2*n+1)/log(3)).
%F A134021 a(n) = A134022(n) + A134023(n) + A134024(n).
%F A134021 0 <= a(n) - A081604(n) <= 1.
%F A134021 a(A134025(n)) = A081604(A134025(n)); a(A134026(n)) = A081604(A134026(n))+1.
%F A134021 a(A134027(n)) = a(n); a(abs(A134028(n))) <= a(n).
%F A134021 a(n) = A064099(n-1) for n>1.
%F A134021 n = Sum_{k=0..a(n)-1} (A059095(A134421(n)-2-k)*3^k), for n > 0. - _Reinhard Zumkeller_, Oct 25 2007
%F A134021 a(n) = A005812(n) + A134023(n).
%e A134021 100 = 1*3^4+1*3^3-1*3^2+0*3^1+1*3^0: a(100) = |++-0+| = 5.
%e A134021 200 = 1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0: a(200) = |+-+++-| = 6.
%e A134021 300 = 1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0: a(300) = |++-0+0| = 6.
%t A134021 a[n_] := Ceiling[Log[3, 2*n+1]]; a[0] = 1; Array[a, 100, 0] (* _Amiram Eldar_, Apr 03 2025 *)
%o A134021 (Python)
%o A134021 def a(n):
%o A134021     if n==0: return 1
%o A134021     s=0
%o A134021     x=0
%o A134021     while n>0:
%o A134021         x=n%3
%o A134021         n=n//3
%o A134021         if x==2:
%o A134021             x=-1
%o A134021             n+=1
%o A134021         s+=1
%o A134021     return s
%o A134021 print([a(n) for n in range(101)]) # _Indranil Ghosh_, Jun 07 2017
%Y A134021 Cf. A005812, A059095, A081604, A134022, A134023, A134024, A134025, A134026, A134027, A134028, A134421.
%K A134021 nonn,base
%O A134021 0,3
%A A134021 _Reinhard Zumkeller_, Oct 19 2007