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-2 of 2 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

A289815 The first of a pair of coprime numbers whose factorizations depend on the ternary representation of n (see Comments for precise definition).

Original entry on oeis.org

1, 2, 1, 3, 6, 3, 1, 2, 1, 4, 10, 5, 12, 30, 15, 4, 10, 5, 1, 2, 1, 3, 6, 3, 1, 2, 1, 5, 14, 7, 15, 42, 21, 5, 14, 7, 20, 70, 35, 60, 210, 105, 20, 70, 35, 5, 14, 7, 15, 42, 21, 5, 14, 7, 1, 2, 1, 3, 6, 3, 1, 2, 1, 4, 10, 5, 12, 30, 15, 4, 10, 5, 1, 2, 1, 3, 6
Offset: 0

Views

Author

Rémy Sigrist, Jul 12 2017

Keywords

Comments

For n >= 0, with ternary representation Sum_{i=1..k} t_i * 3^e_i (all t_i in {1, 2} and all e_i distinct and in increasing order):
- let S(0) = A000961 \ { 1 },
- and S(i) = S(i-1) \ { p^(f + j), with p^f = the (e_i+1)-th term of S(i-1) and j > 0 } for any i=1..k,
- then a(n) = Product_{i=1..k such that t_i=1} "the (e_i+1)-th term of S(k)".
See A289816 for the second coprime number.
See A289838 for the product of this sequence with A289816.
By design, gcd(a(n), A289816(n)) = 1.
Also, the number of distinct prime factors of a(n) equals the number of ones in the ternary representation of n.
We also have a(n) = A289816(A004488(n)) for any n >= 0.
For each pair of coprime numbers, say x and y, there is a unique index, say n, such that a(n) = x and A289816(n) = y; in fact, n = A289905(x,y).
This sequence combines features of A289813 and A289272.
The scatterplot of the first terms of this sequence vs A289816 (both with logarithmic scaling) looks like a triangular cristal.
For any t > 0: we can adapt the algorithm used here and in A289816 in order to uniquely enumerate every tuple of t mutually coprime numbers (see Links section for corresponding program).

Examples

			For n=42:
- 42 = 2*3^1 + 1*3^2 + 1*3^3,
- S(0) = { 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27, 29, ... },
- S(1) = S(0) \ { 3^(1+j) with j > 0 }
       = { 2, 3, 4, 5, 7, 8,    11, 13, 16, 17, 19, 23, 25,     29, ... },
- S(2) = S(1) \ { 2^(2+j) with j > 0 }
       = { 2, 3, 4, 5, 7,       11, 13,     17, 19, 23, 25,     29, ... },
- S(3) = S(2) \ { 5^(1+j) with j > 0 }
       = { 2, 3, 4, 5, 7,       11, 13,     17, 19, 23,         29, ... },
- a(42) = 4 * 5 = 20.
		

Crossrefs

Programs

  • PARI
    a(n) =
    {
        my (v=1, x=1);
        for (o=2, oo,
            if (n==0, return (v));
            if (gcd(x,o)==1 && omega(o)==1,
                if (n % 3,    x *= o);
                if (n % 3==1, v *= o);
                n \= 3;
            );
        );
    }
    
  • Python
    from sympy import gcd, primefactors
    def omega(n): return 0 if n==1 else len(primefactors(n))
    def a(n):
        v, x, o = 1, 1, 2
        while True:
            if n==0: return v
            if gcd(x, o)==1 and omega(o)==1:
                if n%3: x*=o
                if n%3==1:v*=o
                n //= 3
            o+=1
    print([a(n) for n in range(101)]) # Indranil Ghosh, Aug 02 2017

Formula

a(A005836(n)) = A289272(n-1) for any n > 0.
a(2 * A005836(n)) = 1 for any n > 0.
Showing 1-2 of 2 results.