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.

A253047 Start with the natural numbers 1,2,3,...; interchange 2*prime(i) and 3*prime(i+1) for each i, and interchange prime(prime(i)) with prime(2*prime(i)) for each i.

Original entry on oeis.org

1, 2, 7, 9, 13, 15, 3, 8, 4, 21, 29, 12, 5, 33, 6, 16, 43, 18, 19, 20, 10, 39, 23, 24, 25, 51, 27, 28, 11, 30, 79, 32, 14, 57, 35, 36, 37, 69, 22, 40, 101, 42, 17, 44, 45, 87, 47, 48, 49, 50, 26, 52, 53, 54, 55, 56, 34, 93, 139, 60, 61, 111, 63
Offset: 1

Views

Author

N. J. A. Sloane, Dec 26 2014

Keywords

Comments

This is an involution on the natural numbers: applying it twice gives the identity permutation.

Crossrefs

Programs

  • Maple
    f:= proc(t)
    local r;
      if t mod 2 = 0 and isprime(t/2) then  3*nextprime(t/2)
      elif t mod 3 = 0 and isprime(t/3) then 2*prevprime(t/3)
      elif isprime(t) then
        r:= numtheory:-pi(t);
        if isprime(r) then ithprime(2*r)
        elif r mod 2 = 0 and isprime(r/2) then ithprime(r/2)
        else t
        fi
      else t
      fi
    end proc:
    seq(f(i),i=1..100); # Robert Israel, Dec 26 2014
  • Mathematica
    f[t_] := Module[{r}, Which[EvenQ[t] && PrimeQ[t/2], 3 NextPrime[t/2], Divisible[t, 3] && PrimeQ[t/3], 2 NextPrime[t/3, -1], PrimeQ[t], r = PrimePi[t]; Which[PrimeQ[r], Prime[2r], EvenQ[r] && PrimeQ[r/2], Prime[r/2], True, t], True, t]];
    Array[f, 100] (* Jean-François Alcover, Jul 27 2020, after Robert Israel *)
  • Python
    from sympy import isprime, primepi, prevprime, nextprime, prime
    def A253047(n):
        if n <= 2:
            return n
        if n == 3:
            return 7
        q2, r2 = divmod(n,2)
        if r2:
            q3, r3 = divmod(n,3)
            if r3:
                if isprime(n):
                    m = primepi(n)
                    if isprime(m):
                        return prime(2*m)
                    x, y = divmod(m,2)
                    if not y:
                        if isprime(x):
                            return prime(x)
                return n
            if isprime(q3):
                return 2*prevprime(q3)
            return n
        if isprime(q2):
            return 3*nextprime(q2)
        return n # Chai Wah Wu, Dec 27 2014

Extensions

Definition supplied by Robert Israel, Dec 26 2014
Offset changed to 1 by Chai Wah Wu, Dec 27 2014