login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A026234
In the sequence of positive integers, swap the k-th prime and k-th nonprime, for k = 1,2,3,...
7
2, 1, 4, 3, 6, 5, 8, 7, 11, 13, 9, 17, 10, 19, 23, 29, 12, 31, 14, 37, 41, 43, 15, 47, 53, 59, 61, 67, 16, 71, 18, 73, 79, 83, 89, 97, 20, 101, 103, 107, 21, 109, 22, 113, 127, 131, 24, 137, 139, 149, 151, 157, 25, 163, 167, 173, 179, 181
OFFSET
1,1
COMMENTS
A permutation of the positive integers. - M. F. Hasler, Jan 29 2014
FORMULA
If n is prime, then a(n) = A018252(n), else a(n) = A000040(n). - M. F. Hasler, Jan 29 2014
EXAMPLE
a(1) = 2 because 1 is not prime and the first prime is 2.
a(2) = 1 because 2 is prime and the first nonprime is 1.
a(3) = 4 because 3 is prime and the second nonprime is 4.
a(4) = 3 because 4 is not prime and the second prime is 3.
a(5) = 6 because 5 is prime and the third nonprime is 6.
MATHEMATICA
nonPrimePi[n_] := n - PrimePi[n]; nonPrime[n_] := FixedPoint[n + PrimePi[#] &, n + PrimePi[n]]; A026234[n_] := If[PrimeQ[n], nonPrime[PrimePi[n]], Prime[nonPrimePi[n]]]; Table[A026234[n], {n, 200}] (* Enrique Pérez Herrero, Jan 28 2014 *)
PROG
(PARI) c=p=0; vector(99, n, if(isprime(n), while(isprime(c++), ); c, prime(p++))) \\ M. F. Hasler, Jan 29 2014
(PARI) A026234 = n->if(isprime(n), A018252(primepi(n)), prime(n-primepi(n))) \\ M. F. Hasler, Jan 29 2014
CROSSREFS
Sequence in context: A096779 A243500 A026262 * A352726 A317630 A282651
KEYWORD
nonn,easy
STATUS
approved