A236854 Self-inverse permutation of natural numbers: a(1)=1, then a(p_n)=c_{a(n)}, a(c_n)=p_{a(n)}, where p_n = n-th prime, c_n = n-th composite.
1, 4, 9, 2, 16, 7, 6, 23, 3, 53, 26, 17, 14, 13, 83, 5, 12, 241, 35, 101, 59, 43, 8, 41, 431, 11, 37, 1523, 75, 149, 39, 547, 277, 191, 19, 179, 27, 3001, 31, 157, 24, 12763, 22, 379, 859, 167, 114, 3943, 1787, 1153, 67, 1063, 10, 103, 27457, 127, 919, 89, 21
Offset: 1
Keywords
Examples
a(5)=c(a(3))=c(9)=16, because 5=prime(3), and the 9th composite number is c(9)=16. Thus a(10)=prime(a(5))=prime(16)=53 (since 10 is the 5th composite), a(18)=prime(a(10))=prime(53)=241 (since 18 is the 10th composite), a(28)=prime(a(18))=prime(241)=1523. A significant record value is a(198) = prime(a(152)) = prime(563167303) since 198=c(152); a(152)=prime(a(115)) since 152=c(115); a(115)=prime(a(84)); a(84)=prime(a(60)); a(60)=prime(a(42)); a(42)=prime(a(28)).
Links
- Chai Wah Wu, Table of n, a(n) for n = 1..735 (n = 1..150 from Alois P. Heinz)
- Index entries for sequences that are permutations of the natural numbers
Crossrefs
Programs
-
Mathematica
terms = 150; cc = Select[Range[4, 2 terms^2(*empirical*)], CompositeQ]; compositePi[k_?CompositeQ] := FirstPosition[cc, k][[1]]; a[1] = 1; a[p_?PrimeQ] := a[p] = cc[[a[PrimePi[p]]]]; a[k_] := a[k] = Prime[a[ compositePi[k]]]; Array[a, terms] (* Jean-François Alcover, Mar 02 2016 *)
-
PARI
A236854(n)={if(isprime(n), A002808(A236854(primepi(n))), n==1&&return(1);prime(A236854(n-primepi(n)-1)))} \\ without memoization: not much slower. - M. F. Hasler, Feb 03 2014
-
PARI
a236854=vector(999);a236854[1]=1;A236854(n)={a236854[n]&&return(a236854[n]); a236854[n]=if(isprime(n), A002808(A236854(primepi(n))), prime(A236854(n-primepi(n)-1)))} \\ Version with memoization. - M. F. Hasler, Feb 03 2014
-
Python
from sympy import primepi, prime, isprime def a002808(n): m, k = n, primepi(n) + 1 + n while m != k: m, k = k, primepi(k) + 1 + n return m # this function from Chai Wah Wu def a(n): return n if n<2 else a002808(a(primepi(n))) if isprime(n) else prime(a(n - primepi(n) - 1)) print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 07 2017
Formula
Extensions
Values double-checked by M. F. Hasler, Feb 03 2014
Comments