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.

This page as a plain text file.
%I A256420 #26 Oct 15 2024 14:36:50
%S A256420 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,
%T A256420 54,56,13,60,14,64,66,68,70,72,15,76,78,80,17,84,19,88,90,92,21,96,98,
%U A256420 100,102,104,22,108,110,112,114,116,23,120
%N A256420 a(n) = 2n unless n is prime, in which case a(n) = first term not yet present in the sequence.
%C A256420 This is a permutation of the positive integers: twice nonprimes (A139270), interspersed with (odd numbers and twice primes, A256421).
%D A256420 John Mason, Email message, Apr 07 2015
%H A256420 Robert Israel, <a href="/A256420/b256420.txt">Table of n, a(n) for n = 1..10000</a>
%p A256420 N:= 100:
%p A256420 S:= {$1..N}:
%p A256420 R:= NULL;
%p A256420 for n from 1 do
%p A256420   if isprime(n) then if S = {} then break else t:= min(S) fi else t:= 2*n fi;
%p A256420   R:= R, t;
%p A256420   S:= S minus {t}
%p A256420 od:
%p A256420 R;
%o A256420 (Python)
%o A256420 from sympy import primepi, isprime
%o A256420 def A256420(n):
%o A256420     r = int(primepi(n))
%o A256420     def iterfun(f,n=0):
%o A256420         m, k = n, f(n)
%o A256420         while m != k: m, k = k, f(k)
%o A256420         return m
%o A256420     def f(x): return int(r+(m:=x>>1)-primepi(m))
%o A256420     return iterfun(f,r) if isprime(n) else n<<1 # _Chai Wah Wu_, Oct 15 2024
%Y A256420 Cf. A139270, A256421.
%K A256420 nonn
%O A256420 1,1
%A A256420 _N. J. A. Sloane_, Apr 07 2015