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.

Showing 1-8 of 8 results.

A065363 Sum of balanced ternary digits in n. Replace 3^k with 1 in balanced ternary expansion of n.

Original entry on oeis.org

0, 1, 0, 1, 2, -1, 0, 1, 0, 1, 2, 1, 2, 3, -2, -1, 0, -1, 0, 1, 0, 1, 2, -1, 0, 1, 0, 1, 2, 1, 2, 3, 0, 1, 2, 1, 2, 3, 2, 3, 4, -3, -2, -1, -2, -1, 0, -1, 0, 1, -2, -1, 0, -1, 0, 1, 0, 1, 2, -1, 0, 1, 0, 1, 2, 1, 2, 3, -2, -1, 0, -1, 0, 1, 0, 1, 2, -1, 0, 1, 0, 1, 2, 1, 2, 3, 0, 1, 2, 1, 2, 3, 2, 3, 4, -1, 0, 1, 0, 1, 2, 1, 2, 3, 0, 1, 2, 1, 2
Offset: 0

Views

Author

Marc LeBrun, Oct 31 2001

Keywords

Comments

Notation: (3)(1).
Extension to negative n: a(-n) = -a(n). - Franklin T. Adams-Watters, May 13 2009
Row sums of A059095. - Rémy Sigrist, Oct 05 2019

Examples

			5 = + 1(9) - 1(3) - 1(1) -> +1 - 1 - 1 = -1 = a(5).
		

Crossrefs

Cf. A059095, A065364, A053735. See A134452 for iterations.

Programs

  • Maple
    a:= proc(n) `if`(n=0, 0, (d-> `if`(d=2,
          a(q+1)-1, d+a(q)))(irem(n, 3, 'q')))
        end:
    seq(a(n), n=0..120);  # Alois P. Heinz, Jan 09 2020
  • Mathematica
    balTernDigits[0] := {0}; balTernDigits[n_/;n > 0] := Module[{unParsed = n, currRem, currExp = 1, digitList = {}, nextDigit}, While[unParsed > 0, If[unParsed == 3^(currExp - 1), digitList = Append[digitList, 1]; unParsed = 0, currRem = Mod[unParsed, 3^currExp]/3^(currExp - 1); nextDigit = Switch[currRem, 0, 0, 2, -1, 1, 1]; digitList = Append[digitList, nextDigit]; unParsed = unParsed - nextDigit * 3^(currExp - 1)]; currExp++]; digitList = Reverse[digitList]; Return[digitList]]; balTernDigits[n_/;n < 0] := (-1)balTernDigits[Abs[n]]; Table[Plus@@balTernDigits[n], {n, 0, 108}] (* Alonso del Arte, Feb 25 2011 *)
    terVal[lst_List] := Reverse[lst].(3^Range[0, Length[lst] - 1]); maxDig = 4; t = Table[0, {3 * 3^maxDig/2}]; t[[1]] = 1; Do[d = IntegerDigits[Range[0, 3^dig - 1], 3, dig]/.{2 -> -1}; d = Prepend[#, 1]&/@d; t[[terVal/@d]] = Total/@d, {dig, maxDig}]; Prepend[t, 0] (* T. D. Noe, Feb 24 2011 *)
    Array[Total[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 109, 0] (* Michael De Vlieger, Jun 27 2020 *)
  • PARI
    bt(n)=my(d=digits(n,3),c=1); while(c, if(d[1]==2, d=concat(0,d)); c=0; for(i=2,#d, if(d[i]==2,d[i]=-1;d[i-1]+=1;c=1))); d
    a(n)=vecsum(bt(n)) \\ Charles R Greathouse IV, May 07 2020
  • Python
    def a(n):
        s=0
        x=0
        while n>0:
            x=n%3
            n=n//3
            if x==2:
                x=-1
                n+=1
            s+=x
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017
    

Formula

G.f.: (1/(1-x))*Sum_{k>=0} (x^3^k - x^(2*3^k))/(x^((3^k-1)/2)*(1 + x^3^k + x^(2*3^k))). - Franklin T. Adams-Watters, May 13 2009
a(n) = A134024(n) - A134022(n). - Reinhard Zumkeller, Dec 16 2010
a(3*n - 1) = a(n) - 1, a(3*n) = a(n), a(3*n + 1) = a(n) + 1. - Thomas König, Jun 24 2020
a(n) = A053735(2n) - A053735(n). This can be shown with constructing balanced ternary representation of n: Add n and n with carry, and then subtract n from the sum without borrow. - Yifan Xie, Dec 24 2024

A134021 Length of n in balanced ternary representation.

Original entry on oeis.org

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, 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, 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
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Comments

Shifted variant of A064099.

Examples

			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.
		

References

  • Donald E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175.

Crossrefs

Programs

  • Mathematica
    a[n_] := Ceiling[Log[3, 2*n+1]]; a[0] = 1; Array[a, 100, 0] (* Amiram Eldar, Apr 03 2025 *)
  • 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

Formula

For n > 0: a(n) = ceiling(log(2*n+1)/log(3)).
a(n) = A134022(n) + A134023(n) + A134024(n).
0 <= a(n) - A081604(n) <= 1.
a(A134025(n)) = A081604(A134025(n)); a(A134026(n)) = A081604(A134026(n))+1.
a(A134027(n)) = a(n); a(abs(A134028(n))) <= a(n).
a(n) = A064099(n-1) for n>1.
n = Sum_{k=0..a(n)-1} (A059095(A134421(n)-2-k)*3^k), for n > 0. - Reinhard Zumkeller, Oct 25 2007
a(n) = A005812(n) + A134023(n).

A005812 Weight of balanced ternary representation of n.

Original entry on oeis.org

0, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 4, 3, 4, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3
Offset: 0

Views

Author

Keywords

Comments

Weight of n means count of nonzero digits of n. - Daniel Forgues, Mar 24 2010
a(n) = A134022(n) + A134024(n) = A134021(n) - A134023(n).

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Programs

  • Lisp
    (defun btw (n) (if (= n 0) 0 (multiple-value-bind (q r) (round n 3) (+ (abs r) (btw q)))))
    
  • Mathematica
    a[n_] := With[{q=Round[n/3]}, Abs[n-3q]+a[q]]; a[0]=0; Table[a[n], {n, 0, 105}](* Jean-François Alcover, Nov 25 2011, after Pari *)
  • PARI
    a(n)=local(q); if(n<=0,0,q=round(n/3); abs(n-3*q)+a(q))
    
  • Python
    def a(n):
        s=0
        x=0
        while n>0:
            x=n%3
            n//=3
            if x==2:
                x=-1
                n+=1
            if x!=0: s+=1
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017

Formula

a(3n)=a(n), a(3n+1)=a(n)+1, a(9n+2)=a(n)+2, a(9n+5)=a(3n+2)+1, a(9n+8)=a(3n+2).
a(n) = Sum_{k>0} floor(|2*sin(n*Pi/3^k)|). - Toshitaka Suzuki, Sep 10 2006

Extensions

Additional terms from Allan C. Wechsler

A134023 Number of zeros in balanced ternary representation of n.

Original entry on oeis.org

1, 0, 0, 1, 0, 0, 1, 0, 1, 2, 1, 0, 1, 0, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 2, 3, 2, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 2, 3, 2, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 3, 2, 3, 4, 3, 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Examples

			100=1*3^4+1*3^3-1*3^2+0*3^1+1*3^0=='++-0+': a(100)=1;
200=1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0=='+-+++-': a(200)=0;
300=1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0=='++-0+0': a(300)=2.
		

References

  • D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.

Crossrefs

Programs

  • Mathematica
    Array[Count[If[First@ # == 0, Rest@ #, #], 0] &[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 105, 0] (* Michael De Vlieger, Jun 27 2020 *)
  • 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
            if x==0: s+=1
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017

Formula

a(n) = A134021(n) - A134022(n) - A134024(n).
a(n) = A134021(n) - A005812(n).

A134024 Number of positive trits in balanced ternary representation of n.

Original entry on oeis.org

0, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3, 3, 3, 4, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3, 3, 3, 4, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3, 3, 3, 4, 2, 2, 3, 2, 2, 3, 3, 3, 4, 2
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Examples

			100=1*3^4+1*3^3-1*3^2+0*3^1+1*3^0=='++-0+': a(100)=3;
200=1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0=='+-+++-': a(200)=4;
300=1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0=='++-0+0': a(300)=3.
		

References

  • D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.

Crossrefs

Programs

  • Mathematica
    Array[Count[#, 1] &[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 105, 0] (* Michael De Vlieger, Jun 27 2020 *)
  • Python
    def a(n):
        s=0
        x=0
        while n>0:
            x=n%3
            n //= 3
            if x==2:
                x=-1
                n+=1
            if x==1: s+=1
        return s
    print([a(n) for n in range(151)]) # Indranil Ghosh, Jun 07 2017

Formula

a(n) = A134021(n) - A134022(n) - A134023(n);
a(n) > 0 for n > 0.
a(n) = A005812(n) - A134022(n) = A134022(n) + A065363(n).

A379049 a(n) = prime(i)*dp(n,i) + prime(i)*dn(n,i) where dp(n,i) = 1 when the i-th trit of n is 1, dn(n,i) = 1 when the i-th trit of n is T, and dp(n,i) = dn(n,i) = 0 when the i-th trit of n is 0.

Original entry on oeis.org

2, 3, 5, 4, 7, 11, 8, 13, 7, 6, 11, 17, 16, 31, 37, 22, 29, 17, 12, 19, 31, 26, 47, 13, 10, 17, 9, 8, 15, 23, 22, 43, 41, 38, 73, 37, 36, 71, 107, 106, 211, 221, 116, 127, 81, 46, 57, 103, 68, 101, 53, 32, 43, 25, 18, 29, 47, 40, 73, 97, 76, 131, 69, 62, 117
Offset: 0

Views

Author

Lei Zhou, Dec 14 2024

Keywords

Comments

The Balanced Ternary presentation of a number is a series of 1, 0, and T, where T represent -1. For example, 35 = 110T = 1 * 3^3 + 1* 3^2 + 0 * 3 - 1 = 27 + 9 + 0 - 1.
Conjecture: All positive integers greater than 1 appear in this sequence at least once.

Examples

			When n = 0, its BT presentation is 0, thus a(0) = 1 + 1 = 2;
When n = 1, its BT presentation is 1, the first prime is 2, thus a(1) = 2 + 1 = 3;
...
When n = 14, its BT presentation is 1TTT, thus prime 7 appears before the plus sign and primes 5, 3, and 2 appear in the term after the plus sign, a(14) = 7 + 5*3*2 = 37;
...
By the same rule, when n = 64, its BT presentation is 1T101, thus prime 11, 5, 2 appear before the plus sign and prime 7 appears in the term after the plus sign, a(64) = 11*5*2 + 7 = 117.
		

Crossrefs

Programs

  • Mathematica
    BTDigits[m_Integer, g_]:= Module[{n = m, d, sign, t = g}, If[n != 0, If[n > 0, sign = 1, sign = -1; n = -n]; d = Ceiling[Log[3, n]]; If[3^d - n <= ((3^d - 1)/2), d++]; While[Length[t] < d, PrependTo[t, 0]]; t[[Length[t] + 1 - d]] = sign; t = BTDigits[sign*(n - 3^(d - 1)), t]]; t];
    res = {}; Do[BT = BTDigits[i, {0}]; BTl = Length[BT]; f = 1; b = 1; Do[If[BT[[j]] == 1, f = f*Prime[BTl - j + 1]]; If[BT[[j]] == -1, b = b*Prime[BTl - j + 1]], {j, 1, BTl}];  d = f + b; AppendTo[res, d], {i, 0, 64}]; res
  • Python
    from sympy import prime
    def A140267(n): # see A140267
        return
    def A379049(n):
        x,y,z = 1,1,str(A140267(n))[::-1]
        for i in range(len(z)):
            if z[i] == "1":
                x *= prime(i+1)
            if z[i] == "2":
                y *= prime(i+1)
        return x+y # John Tyler Rascoe, Feb 27 2025

A277513 Irregular triangle read by rows: T(n,k) is the number of integers greater than 4 such that they have n trits and 2k+1 (k>=1) nonzero trits in their balanced ternary representation, with n>=3 and 1<=k<=(j-1)/2.

Original entry on oeis.org

4, 12, 24, 16, 40, 80, 60, 240, 64, 84, 560, 448, 112, 1120, 1792, 256, 144, 2016, 5376, 2304, 180, 3360, 13440, 11520, 1024, 220, 5280, 29568, 42240, 11264, 264, 7920, 59136, 126720, 67584, 4096, 312, 11440, 109824, 329472, 292864, 53248, 364, 16016, 192192
Offset: 3

Views

Author

Lei Zhou, Oct 18 2016

Keywords

Comments

This is a subset of A013609 and A188440.
This sequence T(n,k) can be re-indexed into the form of b(m) where m is positive integer sequence that can be calculated by parametric function m = m(n,k): m(n=2j+1,k) = j^2-j+k, where n is odd and 1<=k<=j.
m(n=2j,k) = j^2-2j+1+k, where n is even and 1<=k<=j.
Here n is the number of digits of an odd number in balanced ternary representation, and 2k+1 is the number of nonzero trits (1 or T) of the same number in balanced ternary representation.

Examples

			Odd numbers that can be expressed in 3 trits balanced ternary (bt) form are 5 = 1TT, 7 = 1T1, 9 = 100, 11 = 11T, 13 = 111. Among these five numbers, four have 3 nonzero digits, so a(1) = 4.
Odd numbers in 4 trits bt form are 15 = 1TT0, 17 = 1T0T, 19 = 1T01, 21 = 1T10, 23 = 10TT, 25 = 10T1, 27 = 1000, 29 = 101T, 31 = 1011, 33 = 11T0, 35 = 110T, 37 = 1101, 39 = 1110. Among these 13 numbers, 12 have 3 nonzero digits, so a(2) = 12.
The irregular triangle begins:
        k=1      2      3      4       5      6      7
n=3       4
n=4      12
n=5      24     16
n=6      40     80
n=7      60    240     64
n=8      84    560    448
n=9     112   1120   1792    256
n=10    144   2016   5376   2304
n=11    180   3360  13440  11520    1024
n=12    220   5280  29568  42240   11264
n=13    264   7920  59136 126720   67584   4096
n=14    312  11440 109824 329472  292864  53248
n=15    364  16016 192192 768768 1025024 372736  16384
These are the odd columns with the 1st column removed in the table in A013609.
		

Crossrefs

Programs

  • Mathematica
    a = {}; Do[Do[ct = 2^(2k)*Binomial[n - 1, 2k]; AppendTo[a, ct], {k, 1, Floor[(n-1)/2]}], {n, 3, 15}]; a

Formula

T(n,k) = 2^(2k)*Binomial(n-1, 2k)

A379260 Index of first appearance of n in sequence A379049.

Original entry on oeis.org

0, 1, 3, 2, 9, 4, 6, 26, 24, 5, 18, 7, 78, 28, 12, 11, 54, 19, 216, 71, 15, 29, 162, 53, 21, 73, 231, 16, 486, 13, 51, 217, 84, 83, 36, 14, 33, 647, 57, 32, 4374, 31, 237, 649, 45, 22, 207, 236, 165, 1945, 693, 50, 2151, 212, 90, 46, 87, 160, 39366, 86, 63
Offset: 2

Views

Author

Lei Zhou, Dec 19 2024

Keywords

Comments

a(n) is the smallest integer that makes A379049(a(n)) = n.
Conjecture: a(n) is defined for all integer n > 1.

Examples

			For n = 2, A379049(0) = 1 + 1 = 2.  Thus a(2) = 0;
For n = 3, A379049(1) = 2 + 1 = 3, since 1's balanced ternary representation is 1.  Thus a(3) = 1;
For n = 4, A379049(3) = 3 + 1 = 4, since 3's balanced ternary representation is 10.  Thus a(4) = 3;
...
For n = 60, A379049(39366) = 31 + 29 = 60, since 39366's balanced ternary representation is 1T000000000, where the 11's digit is 1 represents the 11's prime 31 in the term before the plus sign, and the 10's digit is T representing the 10's prime 29 in the term after the plus sign. And evaluation of A379049 found no number i smaller than 39366 can make A379049(i) = 60.  Thus a(60) = 39366.
		

Crossrefs

Programs

  • Mathematica
    BTDigits[m_Integer, g_] :=  Module[{n = m, d, sign, t = g}, If[n != 0, If[n > 0, sign = 1, sign = -1; n = -n]; d = Ceiling[Log[3, n]]; If[3^d - n <= ((3^d - 1)/2), d++];    While[Length[t] < d, PrependTo[t, 0]]; t[[Length[t] + 1 - d]] = sign; t = BTDigits[sign*(n - 3^(d - 1)), t]]; t];
    goal = 62; res = {}; ct = 1;
    Do[AppendTo[res, 0], {i, 2, goal}]; i = -1; While[ct < goal, i++; BT = BTDigits[i, {0}]; BTl = Length[BT]; f = 1; b = 1;  Do[If[BT[[j]] == 1, f = f*Prime[BTl - j + 1]];   If[BT[[j]] == -1, b = b*Prime[BTl - j + 1]], {j, 1, BTl}]; d = f + b; If[(d <= goal) && (res[[d - 1]] == 0), res[[d - 1]] = i; ct++]];
    res
Showing 1-8 of 8 results.