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.

A062756 Number of 1's in ternary (base-3) expansion of n.

Original entry on oeis.org

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

Views

Author

Ahmed Fares (ahmedfares(AT)my-deja.com), Jul 16 2001

Keywords

Comments

Fixed point of the morphism: 0 ->010; 1 ->121; 2 ->232; ...; n -> n(n+1)n, starting from a(0)=0. - Philippe Deléham, Oct 25 2011

Crossrefs

Cf. A080846, A343785 (first differences).
Cf. A081606 (indices of !=0).
Indices of terms 0..6: A005823, A023692, A023693, A023694, A023695, A023696, A023697.
Numbers of: A077267 (0's), A081603 (2's), A160384 (1's+2's).
Other bases: A000120, A160381, A268643.

Programs

  • Haskell
    a062756 0 = 0
    a062756 n = a062756 n' + m `mod` 2 where (n',m) = divMod n 3
    -- Reinhard Zumkeller, Feb 21 2013
    
  • Mathematica
    Table[Count[IntegerDigits[i, 3], 1], {i, 0, 200}]
    Nest[Join[#, # + 1, #] &, {0}, 5] (* IWABUCHI Yu(u)ki, Sep 08 2012 *)
  • PARI
    a(n)=if(n<1,0,a(n\3)+(n%3)%2) \\ Paul D. Hanna, Feb 24 2006
    
  • PARI
    a(n)=hammingweight(digits(n,3)%2); \\ Ruud H.G. van Tol, Dec 10 2023
    
  • Python
    from sympy.ntheory import digits
    def A062756(n): return digits(n,3)[1:].count(1) # Chai Wah Wu, Dec 23 2022

Formula

a(0) = 0, a(3n) = a(n), a(3n+1) = a(n)+1, a(3n+2) = a(n). - Vladeta Jovovic, Jul 18 2001
G.f.: (Sum_{k>=0} x^(3^k)/(1+x^(3^k)+x^(2*3^k)))/(1-x). In general, the generating function for the number of digits equal to d in the base b representation of n (0 < d < b) is (Sum_{k>=0} x^(d*b^k)/(Sum_{i=0..b-1} x^(i*b^k)))/(1-x). - Franklin T. Adams-Watters, Nov 03 2005 [For d=0, use the above formula with d=b: (Sum_{k>=0} x^(b^(k+1))/(Sum_{i=0..b-1} x^(i*b^k)))/(1-x), adding 1 if you consider the representation of 0 to have one zero digit.]
a(n) = a(floor(n/3)) + (n mod 3) mod 2. - Paul D. Hanna, Feb 24 2006

Extensions

More terms from Vladeta Jovovic, Jul 18 2001

A343601 For any positive number n, the ternary representation of a(n) is obtained by right-rotating the ternary representation of n until a nonzero digit appears again as the leftmost digit; a(0) = 0.

Original entry on oeis.org

0, 1, 2, 3, 4, 7, 6, 5, 8, 9, 12, 21, 10, 13, 22, 19, 14, 23, 18, 15, 24, 11, 16, 25, 20, 17, 26, 27, 36, 63, 30, 37, 64, 57, 38, 65, 28, 39, 66, 31, 40, 67, 58, 41, 68, 55, 42, 69, 32, 43, 70, 59, 44, 71, 54, 45, 72, 33, 46, 73, 60, 47, 74, 29, 48, 75, 34, 49
Offset: 0

Views

Author

Rémy Sigrist, Apr 21 2021

Keywords

Comments

This sequence is a permutation of the nonnegative integers with inverse A343600.

Examples

			The first terms, in base 10 and in base 3, are:
  n   a(n)  ter(n)  ter(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     2       2          2
   3     3      10         10
   4     4      11         11
   5     7      12         21
   6     6      20         20
   7     5      21         12
   8     8      22         22
   9     9     100        100
  10    12     101        110
  11    21     102        210
  12    10     110        101
  13    13     111        111
  14    22     112        211
		

Crossrefs

Cf. A053735, A081604, A139706 (binary variant), A160384, A343600 (inverse).

Programs

  • PARI
    a(n, base=3) = { my (d=digits(n, base)); forstep (k=#d, 2, -1, if (d[k], return (fromdigits(concat(d[k..#d], d[1..k-1]), base)))); n }

Formula

A053735(a(n)) = A053735(n).
A081604(a(n)) = A081604(n).
a^k(n) = n for k = A160384(n) (where a^k denotes the k-th iterate of a).

A300956 a(0) = 0, a(1) = 2, a(2) = 1, and for any n > 2 with ternary representation n = Sum_{i=0..k} t_i * 3^i, a(n) = Sum_{i=0..k} a(t_i) * 3^a(i).

Original entry on oeis.org

0, 2, 1, 18, 20, 19, 9, 11, 10, 6, 8, 7, 24, 26, 25, 15, 17, 16, 3, 5, 4, 21, 23, 22, 12, 14, 13, 774840978, 774840980, 774840979, 774840996, 774840998, 774840997, 774840987, 774840989, 774840988, 774840984, 774840986, 774840985, 774841002, 774841004
Offset: 0

Views

Author

Rémy Sigrist, Mar 17 2018

Keywords

Comments

This sequence is a self-inverse permutation of the natural numbers.
This sequence has connections with A300955.
This sequence has infinitely many fixed points (A300958); for any k >= 0, at least one of k or 3^k + 2 * 3^a(k) is a fixed point.

Crossrefs

Cf. A160384, A300955, A300958 (fixed points).

Programs

  • PARI
    a(n) = my (t=Vecrev(digits(n,3))); sum(i=0, #t-1, if (t[i+1]==1, 2, t[i+1]==2, 1, 0) * 3 ^ a(i))

Formula

A160384(a(n)) = A160384(n).
a(a(n)) = n.

A343600 For any positive number n, the ternary representation of a(n) is obtained by left-rotating the ternary representation of n until a nonzero digit appears again as the leftmost digit; a(0) = 0.

Original entry on oeis.org

0, 1, 2, 3, 4, 7, 6, 5, 8, 9, 12, 21, 10, 13, 16, 19, 22, 25, 18, 15, 24, 11, 14, 17, 20, 23, 26, 27, 36, 63, 30, 39, 48, 57, 66, 75, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 54, 45, 72, 33, 42, 51, 60, 69, 78, 29, 32, 35, 38, 41
Offset: 0

Views

Author

Rémy Sigrist, Apr 21 2021

Keywords

Comments

This sequence is a permutation of the nonnegative integers with inverse A343601.

Examples

			The first terms, in base 10 and in base 3, are:
  n   a(n)  ter(n)  ter(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     2       2          2
   3     3      10         10
   4     4      11         11
   5     7      12         21
   6     6      20         20
   7     5      21         12
   8     8      22         22
   9     9     100        100
  10    12     101        110
  11    21     102        210
  12    10     110        101
  13    13     111        111
  14    16     112        121
		

Crossrefs

Cf. A053735, A081604, A139708 (binary variant), A160384, A343601 (inverse).

Programs

  • PARI
    a(n, base=3) = { my (d=digits(n, base)); for (k=2, #d, if (d[k], return (fromdigits(concat(d[k..#d], d[1..k-1]), base)))); n }

Formula

A053735(a(n)) = A053735(n).
A081604(a(n)) = A081604(n).
a^k(n) = n for k = A160384(n) (where a^k denotes the k-th iterate of a).

A333773 Replace 2's with (-1)'s in ternary representation of n and sum nonzero terms with alternating signs.

Original entry on oeis.org

0, 1, -1, 3, 2, 4, -3, -4, -2, 9, 8, 10, 6, 7, 5, 12, 13, 11, -9, -10, -8, -12, -11, -13, -6, -5, -7, 27, 26, 28, 24, 25, 23, 30, 31, 29, 18, 19, 17, 21, 20, 22, 15, 14, 16, 36, 37, 35, 39, 38, 40, 33, 32, 34, -27, -28, -26, -30, -29, -31, -24, -23, -25, -36
Offset: 0

Views

Author

Rémy Sigrist, Apr 05 2020

Keywords

Comments

This sequence is a variant of A117966, and shares features with A065620.
Every integer appears exactly once in this sequence.

Examples

			For n = 97:
- 97 = 3^4 + 3^2 + 2*3^1 + 3^0,
- hence a(97) = 3^4 - 3^2 + (-1)*3^1 - 3^0 = 68.
		

Crossrefs

Programs

  • PARI
    a(n) = { my (v=0, t=Vecrev(digits(n,3))); for (k=1, #t, if (t[k]==1, v=+3^(k-1)-v, t[k]==2, v=-3^(k-1)-v)); v }

Formula

a(3*n) = 3*a(n).
a(3*n+1) = 3*a(n) + (-1)^A160384(n).
a(3*n+2) = 3*a(n) - (-1)^A160384(n).
Sum_{k=0..n} a(k) >= 0 with equality iff n belongs to A024023.
a(n) > 0 iff n belongs to A132141.
a(n) < 0 iff n belongs to A157671.
a(A004488(n)) = -a(n).

A206567 S(m,n) = (number of nonzero terms common to the base 3 expansions of m and n), a symmetric matrix read by antidiagonals.

Original entry on oeis.org

1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 2, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1
Offset: 1

Views

Author

Clark Kimberling, Feb 09 2012

Keywords

Comments

Every nonnegative integer occurs infinitely many times in the matrix.

Examples

			Northwest corner:
1 0 0 1 0 0 1 0 0 1 0 0 1
0 1 0 0 1 0 0 1 0 0 1 0 0
0 0 1 1 1 0 0 0 0 0 0 1 1
1 0 1 2 1 0 1 0 0 1 0 1 2
0 1 1 1 2 0 0 1 0 0 1 1 1
0 0 0 0 0 1 1 1 0 0 0 0 0
1 0 0 1 0 1 2 1 0 1 0 0 1
0 1 0 0 1 1 1 2 0 0 1 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1
1 0 0 1 0 0 1 0 1 2 1 1 2
0 1 0 0 1 0 0 1 1 1 2 1 1
0 0 1 1 1 0 0 0 1 1 1 2 2
1 0 1 2 1 0 1 0 1 2 1 2 3
4 = 3 + 1 and 13 = 3^2 + 3 + 1, so S(13,4)=2.
		

Crossrefs

Cf. A160384, A206479 (similar in base 2).

Programs

  • Maple
    S:= proc(m,n) local M,N;
      M:= convert(m,base,3);
      N:= convert(n,base,3);
      convert(zip((s,t) -> `if`(s=t and s <> 0, 1, 0),M,N),`+`);
    end proc:
    seq(seq(S(k,n-k+1),k=1..n),n=1..30); # Robert Israel, Mar 19 2018
  • Mathematica
    d[n_] := IntegerDigits[n, 3];
    t[n_] := Reverse[Array[d, 100][[n]]]
    s[n_, k_] := Position[t[n], k]
    t[m_, n_] := Sum[Length[Intersection[s[m, k], s[n, k]]], {k, 1, 2}]
    TableForm[Table[t[m, n], {m, 1, 24},
      {n, 1, 24}]]  (* A206567 as a matrix *)
    Flatten[Table[t[i, n + 1 - i], {n, 1, 24},
      {i, 1, n}]]   (* A206567 as a sequence *)
  • PARI
    d(n) = Vecrev(digits(n, 3));
    T(n, k) = {my(dn = d(n), dk = d(k), nb = min(#dn, #dk)); sum(i=1, nb, dn[i] && (dn[i] == dk[i]));} \\ Michel Marcus, Mar 19 2018

Formula

Diagonal entries S(n,n) = A160384(n) since all nonzero digits match. - Robert Israel, Mar 18 2018

Extensions

Edited by Robert Israel, Mar 19 2018

A234538 (Number of positive digits of n written in base 3) modulo 3.

Original entry on oeis.org

0, 1, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 0, 0, 2, 0, 0, 1, 2, 2, 2, 0, 0, 2, 0, 0, 1, 2, 2, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 0, 0, 0, 1, 1, 0, 1, 1, 1, 2, 2, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 0, 0, 0, 1, 1, 0, 1, 1, 1, 2, 2, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 0, 0, 0, 1, 1
Offset: 0

Views

Author

Vladimir Shevelev, Jan 13 2014

Keywords

Comments

Since A000120 is the number of positive digits of n written in binary, this sequence is a formal ternary analog of the Thue-Morse sequence A010060. However, one cannot name it a "ternary version of A010060" like the known versions A053838, A071858, A036577-A036586, since it is not "cubefree"; i.e., it contains the same 3 consecutive terms, and there is not a known morphism for which it is a fixed point.

Crossrefs

Programs

  • Mathematica
    a[n_] := Mod[Plus @@ DigitCount[n, 3, {1, 2}], 3]; Array[a, 100, 0] (* Amiram Eldar, Jul 24 2023 *)
  • PARI
    a(n)=my(d=digits(n, 3)); sum(i=1, #d, !d[i])%3 \\ Charles R Greathouse IV, Jan 13 2014

Formula

A160384(n) == a(n) (mod 3).

A276134 a(5n) = a(n), a(5n+1) = a(5n+2) = a(5n+3) = a(5n+4) = a(n) + 1, a(0) = 0.

Original entry on oeis.org

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

Views

Author

Ilya Gutkovskiy, Aug 21 2016

Keywords

Comments

Number of nonzero digits in the base 5 representation of n.
Fixed point of the mapping 0 -> 01111, 1 -> 12222, 2 -> 23333, ...
Self-similar or fractal sequence (underlining every fifth term, reproduce the original sequence).

Examples

			The evolution starting with 0 is: 0 -> 01111 -> 0111112222122221222212222 -> ...
...
a(0) = 0;
a(1) = a(5*0+1) = a(0) + 1 = 1;
a(2) = a(5*0+2) = a(0) + 1 = 1;
a(3) = a(5*0+3) = a(0) + 1 = 1;
a(4) = a(5*0+4) = a(0) + 1 = 1;
a(5) = a(5*1+0) = a(1) = 1;
a(6) = a(5*1+1) = a(1) + 1 = 2, etc.
...
Also a(10) = 1, because 10 (base 10) = 20 (base 5) and 20 has 1 nonzero digit.
		

Crossrefs

Programs

  • Maple
    f:= n -> nops(subs(0=NULL,convert(n,base,5))):
    map(f, [$0..100]); # Robert Israel, Sep 07 2016
  • Mathematica
    Join[{0}, Table[IntegerLength[n, 5] - DigitCount[n, 5, 0], {n, 120}]]

Formula

a(5^k) = 1.
a(5^k-1) = k.
a(5^k-m) = k, k>0, m = 2,3,4.
a(5^k+m) = 2, k>0, m = 1,2,3,4.
a(5^k-a(5^k)) = k.
a(5^k+(-1)^k) = (k + (-1)^k*(k - 1) + 3)/2.
a(5^k+(-1)^k-1) = A093178(k).
a(5^k+(-1)^k+1) = A000034(k+1), k>0.
G.f. g(x) satisfies g(x) = (1+x+x^2+x^3+x^4)*g(x^5) + (x+x^2+x^3+x^4)/(1-x^5). - Robert Israel, Sep 07 2016

A366344 Irregular triangle T(n, k), n >= 0, k = 1 or 2, read by rows; the n-th row contains two coprime positive integers whose prime factorizations are encoded in the ternary expansion of n (see Comments section for precise definition).

Original entry on oeis.org

1, 1, 2, 1, 1, 2, 3, 1, 4, 1, 3, 2, 1, 3, 2, 3, 1, 4, 5, 1, 6, 1, 5, 2, 9, 1, 8, 1, 9, 2, 5, 3, 10, 3, 3, 4, 1, 5, 2, 5, 1, 6, 3, 5, 4, 3, 3, 10, 1, 9, 2, 9, 1, 8, 7, 1, 10, 1, 7, 2, 15, 1, 12, 1, 15, 2, 7, 3, 14, 3, 5, 4, 25, 1, 18, 1, 25, 2, 27, 1, 16, 1, 27, 2
Offset: 0

Views

Author

Rémy Sigrist, Oct 07 2023

Keywords

Comments

The encoding used here is related to that used for the Doudna sequence (A005940):
- for any pair (u, v) of coprime positive integers, the ternary expansion of the unique n >= 0 such that T(n, 1) = u and T(n, 2) = v is built as follows (from right to left):
- for m = 1, 2, ..., let p be the m-th prime number,
- if p neither divides u nor v then we add a 0,
- if p divides u with multiplicity e then we add a run of e 1's,
- if p divides v with multiplicity e then we add a run of e 2's,
- we also insert an extra 0 between pairs of runs of 1's not separated by 2's and between pairs of runs of 2's not separated by 1's.
This encoding can be applied to any fixed base b >= 2 and will yield a bijection from the nonnegative integers to the set of tuples of b-1 pairwise coprime positive integers.
The case b = 2 corresponds (up to the offset) to the Doudna sequence (A005940).
The sequence n -> T(n, 1) / T(n, 2) runs through all the reduced positive rationals exactly once.

Examples

			Triangle T(n, k) begins (alongside the ternary expansion of n):
  n   n-th row  ter(n)
  --  --------  ------
   0  [1, 1]         0
   1  [2, 1]         1
   2  [1, 2]         2
   3  [3, 1]        10
   4  [4, 1]        11
   5  [3, 2]        12
   6  [1, 3]        20
   7  [2, 3]        21
   8  [1, 4]        22
   9  [5, 1]       100
  10  [6, 1]       101
  11  [5, 2]       102
  12  [9, 1]       110
  13  [8, 1]       111
  14  [9, 2]       112
  15  [5, 3]       120
  16  [10, 3]      121
  17  [3, 4]       122
		

Crossrefs

Programs

  • PARI
    row(n, b = 3) = { my (r = vector(b-1, d, 1), g = 0, t = 0); while (n, my (d = n % b); n \= b; g++; if (d, my (e = 1); while (n % b == d, e++; n \= b;); if (t==d, g--, t = d); r[d] *= prime(g)^e;);); return (r); }

Formula

T(n, 1) = 1 iff n belongs to A005823.
T(n, 2) = 1 iff n belongs to A005836.
T(A005836(n), 1) = A005940(n+1).
T(A005823(n), 2) = A005940(n+1).
A001222(T(n, 1)) = A062756(n).
A001222(T(n, 2)) = A081603(n).
A001222(T(n, 1) * T(n, 2)) = A160384(n).
T(A004488(n), 1) = T(n, 2).
T(A004488(n), 2) = T(n, 1).
T((3^e - 1)/2, 1) = 2^e for any e >= 0.
T(3^e - 1, 2) = 2^e for any e >= 0.
T(3^e, 1) = A000040(e + 1) for any e >= 0.
T(2 * 3^e, 2) = A000040(e + 1) for any e >= 0.
T(3*n, k) = A003961(T(n, k)).
Showing 1-9 of 9 results.