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-9 of 9 results.

A077267 Number of zeros in base-3 expansion of n.

Original entry on oeis.org

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

Views

Author

Henry Bottomley, Nov 01 2002

Keywords

Examples

			a(8)=0 since 8 written in base 3 is 22 with 0 zeros;
a(9)=2 since 9 written in base 3 is 100 with 2 zeros;
a(10)=1 since 10 written in base 3 is 101 with 1 zero.
		

Crossrefs

Programs

Formula

a(1)=a(2)=0; a(3n)=a(n)+1; a(3n+1)=a(3n+2)=a(n). a(3^n-2)=a(3^n-1)=0; a(3^n)=n. a(n)=A077266(n, 3).
a(n) + A062756(n) + A081603(n) = A081604(n). - Reinhard Zumkeller, Mar 23 2003
G.f.: (Sum_{k>=0} x^(3^(k+1))/(1 + x^(3^k) + x^(2*3^k)))/(1-x). - Franklin T. Adams-Watters, Nov 03 2005
a(n) = A079978(n) if n < 3, A079978(n) + a(floor(n/3)) otherwise. - Reinhard Zumkeller, Feb 21 2013

Extensions

a(0)=1 added, offset changed to 0 and b-file adjusted by Reinhard Zumkeller, Feb 21 2013
Wrong formula deleted by Reinhard Zumkeller, Feb 21 2013

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

A134022 Number of negative trits in balanced ternary representation of n.

Original entry on oeis.org

0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 0, 0, 3, 2, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 0, 0, 4, 3, 3, 3, 2, 2, 3, 2, 2, 3, 2, 2, 2, 1, 1, 2, 1, 1, 3, 2, 2, 2, 1, 1, 2, 1, 1, 3, 2, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 0, 0, 3, 2, 2, 2, 1, 1, 2, 1, 1, 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) = 1;
200 = 1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0 == '+-+++-': a(200) = 2;
300 = 1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0 == '++-0+0': a(300) = 1.
		

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=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) - A134023(n) - A134024(n).
a(n) = A005812(n) - A134024(n) = A134024(n) - A065363(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)

A277514 Irregular triangle read by rows: T(n,k) is the number of primes with n balanced ternary digits of which 2k+1 (3 <= 2k+1 <= n) are nonzero.

Original entry on oeis.org

4, 6, 8, 10, 7, 35, 11, 70, 30, 7, 129, 143, 10, 191, 458, 93, 11, 262, 1112, 605, 11, 370, 2209, 2513, 273, 8, 484, 4007, 7646, 2562, 10, 595, 6683, 19361, 12878, 938, 9, 765, 10697, 42633, 47555, 10311, 11, 917, 16103, 85860, 143382, 62541, 3183
Offset: 3

Views

Author

Lei Zhou, Oct 18 2016

Keywords

Comments

This sequence has the same indexing rule as A277513.
There are no zeros in this sequence up to the (10^5)-th term.
It is conjectured that all terms of this sequence are greater than zero, or else there are infinitely many zero terms. The first zero term might appear beyond 10^6.

Examples

			When n=3 and k=1, there are the following three trits balanced ternary numbers: 5=1TT, 7=1T1, 11=11T, 13=111. All four of them are primes, so T(3,1) = 4;
When n=4 and k=1, there are the following balanced ternary numbers with 2k+1=3 nonzero trits: 17=1T0T, 19=1T01, 23=10TT, 25=10T1, 29=101T, 31=1011, 35=110T, 37=1101. Among these 8 numbers, 6 of them are prime, so T(4,1) = 6.
By listing the first few rows, this sequence appears as:
        k=1        2        3        4
n=3       4
n=4       6
n=5       8       10
n=6       7       35
n=8      11       70       30
n=9       7      129      143
n=10     10      191      458       93
		

Crossrefs

2 together with the column 1 gives A196698.

Programs

  • Mathematica
    (* This converts number m to balanced ternary form, stores the result in list t. *)
    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];
    (* This calculates j and k for balanced ternary form of number m. *)
    BTnonzeroNumofDigits[m_Integer] :=
      Module[{n = m}, t = BTDigits[n, {}]; j = Length[t];
       k = 0; Do[If[t[[i]] != 0, k++], {i, 1, j}];
       k = (k - 1)/2; {j, k}];
    (* This calculates the category index n as defined in A277513 for a {j,k} pair. *)
    IndexA277513[{j_, k_}] :=
      Module[{m, i},
       If[OddQ[j], m = (j - 1)/2; i = m^2 - m + k, m = j/2;
        i = m^2 - 2 m + 1 + k]];
    (* This counts a(n). *)
    p=3;a={} ;While[p = NextPrime[p]; jk = BTnonzeroNumofDigits[p]; jk[[1]] <= 15, id = IndexA277513[jk]; While[Length[a] < id, AppendTo[a, 0]];
      a[[id]]++];a

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-9 of 9 results.