login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

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

%I #26 Oct 15 2024 14:36:50

%S 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 54,56,13,60,14,64,66,68,70,72,15,76,78,80,17,84,19,88,90,92,21,96,98,

%U 100,102,104,22,108,110,112,114,116,23,120

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

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

%D John Mason, Email message, Apr 07 2015

%H Robert Israel, <a href="/A256420/b256420.txt">Table of n, a(n) for n = 1..10000</a>

%p N:= 100:

%p S:= {$1..N}:

%p R:= NULL;

%p for n from 1 do

%p if isprime(n) then if S = {} then break else t:= min(S) fi else t:= 2*n fi;

%p R:= R, t;

%p S:= S minus {t}

%p od:

%p R;

%o (Python)

%o from sympy import primepi, isprime

%o def A256420(n):

%o r = int(primepi(n))

%o def iterfun(f,n=0):

%o m, k = n, f(n)

%o while m != k: m, k = k, f(k)

%o return m

%o def f(x): return int(r+(m:=x>>1)-primepi(m))

%o return iterfun(f,r) if isprime(n) else n<<1 # _Chai Wah Wu_, Oct 15 2024

%Y Cf. A139270, A256421.

%K nonn

%O 1,1

%A _N. J. A. Sloane_, Apr 07 2015