OFFSET
1,2
COMMENTS
A reordering of the natural numbers.
The sequence is self-inverse in that a(a(n))=n.
If n is a prime, then a(n+1) is the next prime > n. Hence, the subsequence 2, a(2+1), a(a(2+1)+1), a(a(a(2+1)+1)+1), a(a(a(a(2+1)+1)+1)+1), ... generates the sequence of primes A000040.
LINKS
Hieronymus Fischer, Table of n, a(n) for n = 1..10000
FORMULA
a(1)=1, a(n)=p (where p is the least prime number > a(k) for 1<=k<n) if the minimal natural number not yet in the sequence is greater than a(n-1), else a(n)=a(n-1)-1.
a(n)<>n for all n>3.
p(n+1)=a(p(n)+1), where p(n) is the n-th prime.
a(n+1)=p(m+2), if a(n)-1 is the m-th prime, else a(n+1)=a(n)-1, for n>2.
a(n)=p(m)+p(m-1)-n+1, where m is the least index such that p(m)>n-1 (valid for n>2).
EXAMPLE
a(4)=5, since 5 is the least prime > a(1), a(2), a(3), and the minimal number not yet in the sequence (=4) is greater than 3=a(3).
a(5)=4, since 4 is not in the set {1,2,3,5}={a(k)| 1<=k<n}.
7=p(4)=a(p(3)+1)=a(a(p(2)+1)+1)= a(a(a(p(1)+1)+1)+1)= a(a(a(2+1)+1)+1).
CROSSREFS
KEYWORD
nonn
AUTHOR
Hieronymus Fischer, Apr 30 2012
STATUS
approved