%I #17 Oct 28 2022 17:10:02
%S 1,2,3,5,4,7,6,8,9,11,10,12,13,17,15,19,14,16,18,20,21,23,25,29,22,24,
%T 26,27,28,31,30,32,33,37,35,39,41,43,47,49,34,38,36,40,42,44,45,46,51,
%U 53,55,59,57,61,50,52,65,67,48,54,71,73,63,69,56,58,60,62,64,66,68,70
%N Smallest number not occurring earlier and coprime to a(ceiling(n/2)); a(1)=1.
%C a(2*n) > a(2*n-1).
%C Permutation of the natural numbers with inverse A098313: A098312(n) = a(a(n)).
%H Reinhard Zumkeller, <a href="/A098311/b098311.txt">Table of n, a(n) for n = 1..10000</a>
%H Michael De Vlieger, <a href="/A098311/a098311.png">Log log scatterplot of a(n)</a>, n = 1..2^12, showing records in red, local minima in blue, highlighting primes in green and other prime powers in gold.
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%t nn = 72; c[_] = False; Set[{a[1], c[1]}, {1, True}]; u = 2; Do[Set[{j, k}, {a[Ceiling[n/2]], u}]; While[Nand[! c[k], CoprimeQ[j, k]], k++]; Set[{a[n], c[k]}, {k, True}]; If[k == u, While[c[u], u++]], {n, 2, nn}]; Array[a, nn] (* _Michael De Vlieger_, Oct 28 2022 *)
%o (Haskell)
%o import Data.List ((\\))
%o a098311 n = a098311_list !! (n-1)
%o a098311_list = 1 : ys where
%o ys = 2 : f ys [3..] where
%o f (v:vs) ws = us ++ f vs (ws \\ us) where
%o us = take 2 $ filter ((== 1) . (gcd v)) ws
%o -- _Reinhard Zumkeller_, Oct 11 2014
%K nonn
%O 1,2
%A _Reinhard Zumkeller_, Sep 02 2004
%E Typo in definition fixed by _Reinhard Zumkeller_, Oct 11 2014