%I #23 Jan 12 2025 14:56:05
%S 1,2,3,4,5,6,7,8,11,9,13,10,17,12,19,14,23,18,37,15,29,21,43,16,31,26,
%T 61,20,41,28,71,22,47,34,89,27,67,52,163,24,53,42,113,32,79,60,193,25,
%U 59,45,131,38,103,84,293,30,73,57,181,40,109,95,359,33,83,65,223,49,149,119,463,39,107,91,337,72,241,209,971,35,97,74,251,58
%N Permutation of natural numbers: a(1)=1; a(2n) = not_an_oddprime(1+a(n)), a(2n+1) = oddprime(a(n)).
%C Here oddprime(n) = n-th odd prime = A065091(n) = A000040(n+1), not_an_oddprime(n) = n-th natural number which is not an odd prime = A065090(n).
%C This sequence can be represented as a binary tree. Each left hand child is produced as A065090(1+n), and each right hand child as A065091(n), when a parent contains n >= 1:
%C |
%C ...................1...................
%C 2 3
%C 4......../ \........5 6......../ \........7
%C / \ / \ / \ / \
%C / \ / \ / \ / \
%C / \ / \ / \ / \
%C 8 11 9 13 10 17 12 19
%C 14 23 18 37 15 29 21 43 16 31 26 61 20 41 28 71
%C etc.
%C Because all odd primes are odd, it means that even terms can only occur in even positions (together with odd composites, A071904, for each one of which there is a separate infinite cycle), while terms in odd positions are all odd.
%H Antti Karttunen, <a href="/A257728/b257728.txt">Table of n, a(n) for n = 1..4096</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F a(1) = 1; a(2n) = A065090(1+a(n)), a(2n+1) = A065091(a(n)).
%F As a composition of other permutations:
%F a(n) = A257729(A246378(n)).
%F a(n) = A257802(A257726(n)).
%o (PARI)
%o A002808(n) = { my(k=-1); while( -n + n += -k + k=primepi(n), ); n }; \\ This function from _M. F. Hasler_
%o A257728(n) = if(n<3, n, if(!(n%2), A002808(A257728(n/2)-1), prime(1+A257728((n-1)/2))));
%o for(n=1, 4096, write("b257728.txt", n, " ", A257728(n)));
%o (Scheme)
%o ;; With memoizing definec-macro.
%o (definec (A257728 n) (cond ((< n 2) n) ((even? n) (A065090 (+ 1 (A257728 (/ n 2))))) (else (A065091 (A257728 (/ (- n 1) 2))))))
%Y Inverse: A257727.
%Y Cf. A002808, A065090, A065091, A071904.
%Y Related or similar permutations: A246377, A246378, A257726, A257729, A257802.
%Y Differs from A255004 for the first time at n=17, where a(17) = 23, while A255004(17) = 15.
%K nonn
%O 1,2
%A _Antti Karttunen_, May 09 2015