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.

A256420 a(n) = 2n unless n is prime, in which case a(n) = first term not yet present in the sequence.

Original entry on oeis.org

2, 1, 3, 8, 4, 12, 5, 16, 18, 20, 6, 24, 7, 28, 30, 32, 9, 36, 10, 40, 42, 44, 11, 48, 50, 52, 54, 56, 13, 60, 14, 64, 66, 68, 70, 72, 15, 76, 78, 80, 17, 84, 19, 88, 90, 92, 21, 96, 98, 100, 102, 104, 22, 108, 110, 112, 114, 116, 23, 120
Offset: 1

Views

Author

N. J. A. Sloane, Apr 07 2015

Keywords

Comments

This is a permutation of the positive integers: twice nonprimes (A139270), interspersed with (odd numbers and twice primes, A256421).

References

  • John Mason, Email message, Apr 07 2015

Crossrefs

Programs

  • Maple
    N:= 100:
    S:= {$1..N}:
    R:= NULL;
    for n from 1 do
      if isprime(n) then if S = {} then break else t:= min(S) fi else t:= 2*n fi;
      R:= R, t;
      S:= S minus {t}
    od:
    R;
  • Python
    from sympy import primepi, isprime
    def A256420(n):
        r = int(primepi(n))
        def iterfun(f,n=0):
            m, k = n, f(n)
            while m != k: m, k = k, f(k)
            return m
        def f(x): return int(r+(m:=x>>1)-primepi(m))
        return iterfun(f,r) if isprime(n) else n<<1 # Chai Wah Wu, Oct 15 2024