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.

A004488 Tersum n + n.

Original entry on oeis.org

0, 2, 1, 6, 8, 7, 3, 5, 4, 18, 20, 19, 24, 26, 25, 21, 23, 22, 9, 11, 10, 15, 17, 16, 12, 14, 13, 54, 56, 55, 60, 62, 61, 57, 59, 58, 72, 74, 73, 78, 80, 79, 75, 77, 76, 63, 65, 64, 69, 71, 70, 66, 68, 67, 27, 29, 28, 33, 35, 34, 30, 32, 31, 45, 47, 46, 51
Offset: 0

Views

Author

Keywords

Comments

Could also be described as "Write n in base 3, then replace each digit with its base-3 negative" as with A048647 for base 4. - Henry Bottomley, Apr 19 2000
a(a(n)) = n, a self-inverse permutation of the nonnegative integers. - Reinhard Zumkeller, Dec 19 2003
First 3^n terms of the sequence form a permutation s(n) of 0..3^n-1, n>=1; the number of inversions of s(n) is A016142(n-1). - Gheorghe Coserea, Apr 23 2018

Crossrefs

Programs

  • Haskell
    a004488 0 = 0
    a004488 n = if d == 0 then 3 * a004488 n' else 3 * a004488 n' + 3 - d
                where (n', d) = divMod n 3
    -- Reinhard Zumkeller, Mar 12 2014
    
  • Maple
    a:= proc(n) local t, r, i;
          t, r:= n, 0;
          for i from 0 while t>0 do
            r:= r+3^i *irem(2*irem(t, 3, 't'), 3)
          od; r
        end:
    seq(a(n), n=0..80);  # Alois P. Heinz, Sep 07 2011
  • Mathematica
    a[n_] := FromDigits[Mod[3-IntegerDigits[n, 3], 3], 3]; Table[a[n], {n, 0, 66}] (* Jean-François Alcover, Mar 03 2014 *)
  • PARI
    a(n) = my(b=3); fromdigits(apply(d->(b-d)%b, digits(n, b)), b);
    vector(67, i, a(i-1))  \\ Gheorghe Coserea, Apr 23 2018
    
  • Python
    from sympy.ntheory.factor_ import digits
    def a(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3) # Indranil Ghosh, Jun 06 2017

Formula

Tersum m + n: write m and n in base 3 and add mod 3 with no carries, e.g., 5 + 8 = "21" + "22" = "10" = 1.
a(n) = Sum(3-d(i)-3*0^d(i): n=Sum(d(i)*3^d(i): 0<=d(i)<3)). - Reinhard Zumkeller, Dec 19 2003
a(3*n) = 3*a(n), a(3*n+1) = 3*a(n)+2, a(3*n+2) = 3*a(n)+1. - Robert Israel, May 09 2014

A289813 A binary encoding of the ones in ternary representation of n (see Comments for precise definition).

Original entry on oeis.org

0, 1, 0, 2, 3, 2, 0, 1, 0, 4, 5, 4, 6, 7, 6, 4, 5, 4, 0, 1, 0, 2, 3, 2, 0, 1, 0, 8, 9, 8, 10, 11, 10, 8, 9, 8, 12, 13, 12, 14, 15, 14, 12, 13, 12, 8, 9, 8, 10, 11, 10, 8, 9, 8, 0, 1, 0, 2, 3, 2, 0, 1, 0, 4, 5, 4, 6, 7, 6, 4, 5, 4, 0, 1, 0, 2, 3, 2, 0, 1, 0, 16
Offset: 0

Views

Author

Rémy Sigrist, Jul 12 2017

Keywords

Comments

The ones in the binary representation of a(n) correspond to the ones in the ternary representation of n; for example: ternary(42) = 1120 and binary(a(42)) = 1100 (a(42) = 12).
See A289814 for the sequence encoding the twos in ternary representation of n.
By design, a(n) AND A289814(n) = 0 (where AND stands for the bitwise AND operator).
See A289831 for the sum of this sequence and A289814.
For each pair of numbers without common bits in base 2 representation, say x and y, there is a unique index, say n, such that a(n) = x and A289814(n) = y; in fact, n = A289869(x,y).
The scatterplot of this sequence vs A289814 looks like a Sierpinski triangle pivoted to the side.
For any t > 0: we can adapt the algorithm used here and in A289814 in order to uniquely enumerate every tuple of t numbers mutually without common bits in base 2 representation.

Examples

			The first values, alongside the ternary representation of n, and the binary representation of a(n), are:
n       a(n)    ternary(n)  binary(a(n))
--      ----    ----------  ------------
0       0       0           0
1       1       1           1
2       0       2           0
3       2       10          10
4       3       11          11
5       2       12          10
6       0       20          0
7       1       21          1
8       0       22          0
9       4       100         100
10      5       101         101
11      4       102         100
12      6       110         110
13      7       111         111
14      6       112         110
15      4       120         100
16      5       121         101
17      4       122         100
18      0       200         0
19      1       201         1
20      0       202         0
21      2       210         10
22      3       211         11
23      2       212         10
24      0       220         0
25      1       221         1
26      0       222         0
		

Crossrefs

Programs

  • Mathematica
    Table[FromDigits[#, 2] &[IntegerDigits[n, 3] /. 2 -> 0], {n, 0, 81}] (* Michael De Vlieger, Jul 20 2017 *)
  • PARI
    a(n) = my (d=digits(n,3)); fromdigits(vector(#d, i, if (d[i]==1, 1, 0)), 2)
    
  • PARI
    a(n) = fromdigits(digits(n, 3)%2, 2); \\ Ruud H.G. van Tol, May 08 2024
    
  • Python
    from sympy.ntheory.factor_ import digits
    def a(n):
        d = digits(n, 3)[1:]
        return int("".join('1' if i==1 else '0' for i in d), 2)
    print([a(n) for n in range(51)]) # Indranil Ghosh, Jul 20 2017

Formula

a(0) = 0.
a(3*n) = 2 * a(n).
a(3*n+1) = 2 * a(n) + 1.
a(3*n+2) = 2 * a(n).
Also, a(n) = A289814(A004488(n)).
A053735(n) = A000120(a(n)) + 2*A000120(A289814(n)). - Antti Karttunen, Jul 20 2017

A343228 A binary encoding of the digits "+1" in balanced ternary representation of n.

Original entry on oeis.org

0, 1, 2, 2, 3, 4, 4, 5, 4, 4, 5, 6, 6, 7, 8, 8, 9, 8, 8, 9, 10, 10, 11, 8, 8, 9, 8, 8, 9, 10, 10, 11, 12, 12, 13, 12, 12, 13, 14, 14, 15, 16, 16, 17, 16, 16, 17, 18, 18, 19, 16, 16, 17, 16, 16, 17, 18, 18, 19, 20, 20, 21, 20, 20, 21, 22, 22, 23, 16, 16, 17, 16
Offset: 0

Views

Author

Rémy Sigrist, Apr 08 2021

Keywords

Comments

The ones in the binary representation of a(n) correspond to the digits "+1" in the balanced ternary representation of n.
We can extend this sequence to negative indices: a(-n) = A343229(n) for any n >= 0.

Examples

			The first terms, alongside the balanced ternary representation of n (with "T" instead of digits "-1") and the binary representation of a(n), are:
  n   a(n)  ter(n)  bin(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     2      1T         10
   3     2      10         10
   4     3      11         11
   5     4     1TT        100
   6     4     1T0        100
   7     5     1T1        101
   8     4     10T        100
   9     4     100        100
  10     5     101        101
  11     6     11T        110
  12     6     110        110
  13     7     111        111
  14     8    1TTT       1000
  15     8    1TT0       1000
		

Crossrefs

Programs

  • PARI
    a(n) = { my (v=0, b=1, t); while (n, t=centerlift(Mod(n, 3)); if (t==+1, v+=b); n=(n-t)\3; b*=2); v }

Formula

a(n) = A289831(A060372(n)).

A343231 A binary encoding of the nonzero digits in balanced ternary representation of n.

Original entry on oeis.org

0, 1, 3, 2, 3, 7, 6, 7, 5, 4, 5, 7, 6, 7, 15, 14, 15, 13, 12, 13, 15, 14, 15, 11, 10, 11, 9, 8, 9, 11, 10, 11, 15, 14, 15, 13, 12, 13, 15, 14, 15, 31, 30, 31, 29, 28, 29, 31, 30, 31, 27, 26, 27, 25, 24, 25, 27, 26, 27, 31, 30, 31, 29, 28, 29, 31, 30, 31, 23
Offset: 0

Views

Author

Rémy Sigrist, Apr 08 2021

Keywords

Comments

The ones in the binary representation of a(n) correspond to the nonzero digits in the balanced ternary representation of n.
We can extend this sequence to negative indices: a(-n) = a(n) for any n >= 0.

Examples

			The first terms, alongside the balanced ternary representation of n (with "T" instead of digits "-1") and the binary representation of a(n), are:
  n   a(n)  ter(n)  bin(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     3      1T         11
   3     2      10         10
   4     3      11         11
   5     7     1TT        111
   6     6     1T0        110
   7     7     1T1        111
   8     5     10T        101
   9     4     100        100
  10     5     101        101
  11     7     11T        111
  12     6     110        110
  13     7     111        111
  14    15    1TTT       1111
  15    14    1TT0       1110
		

Crossrefs

Programs

  • PARI
    a(n) = { my (v=0, b=1, t); while (n, t=centerlift(Mod(n, 3)); if (t, v+=b); n=(n-t)\3; b*=2); v }

Formula

a(n) = A343228(n) + A343229(n).

A343229 A binary encoding of the digits "-1" in balanced ternary representation of n.

Original entry on oeis.org

0, 0, 1, 0, 0, 3, 2, 2, 1, 0, 0, 1, 0, 0, 7, 6, 6, 5, 4, 4, 5, 4, 4, 3, 2, 2, 1, 0, 0, 1, 0, 0, 3, 2, 2, 1, 0, 0, 1, 0, 0, 15, 14, 14, 13, 12, 12, 13, 12, 12, 11, 10, 10, 9, 8, 8, 9, 8, 8, 11, 10, 10, 9, 8, 8, 9, 8, 8, 7, 6, 6, 5, 4, 4, 5, 4, 4, 3, 2, 2, 1, 0
Offset: 0

Views

Author

Rémy Sigrist, Apr 08 2021

Keywords

Comments

The ones in the binary representation of a(n) correspond to the digits "-1" in the balanced ternary representation of n.
We can extend this sequence to negative indices: a(-n) = A343228(n) for any n >= 0.

Examples

			The first terms, alongside the balanced ternary representation of n (with "T" instead of digits "-1") and the binary representation of a(n), are:
  n   a(n)  ter(n)  bin(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     0       1          0
   2     1      1T          1
   3     0      10          0
   4     0      11          0
   5     3     1TT         11
   6     2     1T0         10
   7     2     1T1         10
   8     1     10T          1
   9     0     100          0
  10     0     101          0
  11     1     11T          1
  12     0     110          0
  13     0     111          0
  14     7    1TTT        111
  15     6    1TT0        110
		

Crossrefs

Programs

  • PARI
    a(n) = { my (v=0, b=1, t); while (n, t=centerlift(Mod(n, 3)); if (t==-1, v+=b); n=(n-t)\3; b*=2); v }

Formula

a(n) = A289831(A060373(n)).

A368229 Irregular table of nonnegative integers T(n, k), n >= 0, k = 1..A001316(n), read by rows: the 1's in the binary expansion of n exactly match the nonzero digits in the ternary expansions of the terms in the n-th row.

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, Dec 18 2023

Keywords

Comments

As a flat sequence, this is a permutation of the nonnegative integers (with inverse A368230).

Examples

			Table T(n, k) begins:
    0;
    1, 2;
    3, 6;
    4, 5, 7, 8;
    9, 18;
    10, 11, 19, 20;
    12, 15, 21, 24;
    13, 14, 16, 17, 22, 23, 25, 26;
    27, 54;
    28, 29, 55, 56;
    30, 33, 57, 60;
    31, 32, 34, 35, 58, 59, 61, 62;
    36, 45, 63, 72;
    37, 38, 46, 47, 64, 65, 73, 74;
    39, 42, 48, 51, 66, 69, 75, 78;
    40, 41, 43, 44, 49, 50, 52, 53, 67, 68, 70, 71, 76, 77, 79, 80;
    81, 162;
    ...
		

Crossrefs

See A368225 for a similar sequence.

Programs

  • PARI
    row(n) = { my (r = [0], b = binary(n)); for (k = 1, #b, r = [3*v+b[k]|v<-r]; if (b[k], r = concat(r, [v+1|v<-r]););); Set(r); }

Formula

T(n, 1) = A005836(n + 1).
T(n, A001316(n)) = A005823(n + 1).
A289831(T(n, k)) = n.

A374363 a(n) is the greatest term t <= n of A005836 such that n - t also belongs to A005836.

Original entry on oeis.org

0, 1, 1, 3, 4, 4, 3, 4, 4, 9, 10, 10, 12, 13, 13, 12, 13, 13, 9, 10, 10, 12, 13, 13, 12, 13, 13, 27, 28, 28, 30, 31, 31, 30, 31, 31, 36, 37, 37, 39, 40, 40, 39, 40, 40, 36, 37, 37, 39, 40, 40, 39, 40, 40, 27, 28, 28, 30, 31, 31, 30, 31, 31, 36, 37, 37, 39, 40
Offset: 0

Views

Author

Rémy Sigrist, Jul 06 2024

Keywords

Comments

To compute a(n): in the ternary expansion of n, 2's by 1's.

Examples

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

Crossrefs

Programs

  • PARI
    a(n) = fromdigits(apply(d -> [0, 1, 1][1+d], digits(n, 3)), 3)

Formula

a(n) = T(n, A120880(k)-1).
a(n) = n - A374362(n).
a(n) <= n with equality iff n belongs to A005836.
a(n) = A005836(1+A289831(n)).

A344511 a(n) = Sum_{k >= 0} sign(d_k) * 2^k for any number n with decimal expansion Sum_{k >= 0} d_k * 10^k.

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, May 21 2021

Keywords

Comments

The binary expansion of a(n) encodes the nonzero digits of the decimal expansion of n.

Examples

			For n = 20!:
- 2432902008176640000 is the decimal expansion of 20!, so
  1111101001111110000 is the binary expansion of a(20!),
- a(20!) = 513008.
		

Crossrefs

Cf. A007088, A140900, A289831 (base-3 analog), A343452.

Programs

  • PARI
    a(n) = fromdigits(apply(sign, digits(n)), 2)
    
  • Python
    def a(n): return int("".join((('1' if d!='0' else '0') for d in str(n))), 2)
    print([a(n) for n in range(87)]) # Michael S. Branicky, May 22 2021

Formula

a(n) belongs to A140900 iff n belongs to A343452.
a(A007088(n)) = n.

A345359 Lexicographically earliest sequence of distinct nonnegative integers such that the product of two terms, not necessarily distinct, can be computed without carry in base 3.

Original entry on oeis.org

0, 1, 3, 4, 9, 10, 12, 27, 28, 30, 31, 36, 81, 82, 84, 85, 90, 93, 108, 243, 244, 246, 247, 252, 253, 255, 270, 279, 324, 729, 730, 732, 733, 738, 739, 741, 756, 759, 765, 810, 837, 972, 2187, 2188, 2190, 2191, 2196, 2197, 2199, 2214, 2215, 2217, 2218, 2223
Offset: 1

Views

Author

Rémy Sigrist, Jun 16 2021

Keywords

Comments

All terms belong to A005836.
If m is a term, then 3*m is also a term (in particular, all powers of 3 appear in the sequence).
The representation of the 1's in the ternary expansion of consecutive terms has interesting features (see illustration in Links section).

Crossrefs

Cf. A005836, A053735, A131577 (binary analog), A289831, A345358 (decimal analog).

Programs

  • PARI
    See Links section.

Formula

A053735(a(m) * a(n)) = A053735(a(m)) * A053735(a(n)).
Showing 1-9 of 9 results.