login
a(1)=1, a(n)=a(n-1)-1 if a(n-1)-1 > 0 is not in the set {a(k)| 1<=k<n}, else a(n)=p, where p is the least prime number not yet in the sequence.
2

%I #12 Aug 09 2017 23:07:40

%S 1,2,3,5,4,7,6,11,10,9,8,13,12,17,16,15,14,19,18,23,22,21,20,29,28,27,

%T 26,25,24,31,30,37,36,35,34,33,32,41,40,39,38,43,42,47,46,45,44,53,52,

%U 51,50,49,48,59,58,57,56,55,54,61,60,67,66,65,64,63,62,71

%N a(1)=1, a(n)=a(n-1)-1 if a(n-1)-1 > 0 is not in the set {a(k)| 1<=k<n}, else a(n)=p, where p is the least prime number not yet in the sequence.

%C A reordering of the natural numbers.

%C The sequence is self-inverse in that a(a(n))=n.

%C 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.

%H Hieronymus Fischer, <a href="/A210882/b210882.txt">Table of n, a(n) for n = 1..10000</a>

%F 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.

%F a(n)<>n for all n>3.

%F p(n+1)=a(p(n)+1), where p(n) is the n-th prime.

%F 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.

%F 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).

%e 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).

%e a(5)=4, since 4 is not in the set {1,2,3,5}={a(k)| 1<=k<n}.

%e 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).

%Y Cf. A020703, A000040, A038722, A132666, A132664, A132665, A132674, A182194.

%K nonn

%O 1,2

%A _Hieronymus Fischer_, Apr 30 2012