login
A103865
a(1) = 1; a(n) is the smallest positive integer not occurring earlier in the sequence if n is a composite. a(n) = a(n-1)th smallest positive integer among those not occurring earlier in the sequence if n is prime.
4
1, 2, 4, 3, 7, 5, 11, 6, 8, 9, 19, 10, 22, 12, 13, 14, 30, 15, 33, 16, 17, 18, 40, 20, 21, 23, 24, 25, 53, 26, 56, 27, 28, 29, 31, 32, 68, 34, 35, 36, 76, 37, 79, 38, 39, 41, 87, 42, 43, 44, 45, 46, 98, 47, 48, 49, 50, 51, 109, 52, 112, 54, 55, 57, 58, 59, 125, 60, 61, 62, 132
OFFSET
1,2
COMMENTS
Sequence is a permutation of the positive integers.
EXAMPLE
Since 5 is prime, a(5) = a(4)th (3rd) smallest positive integer not occurring earlier in the sequence. The terms not occurring earlier in the sequence are 5,6,7,8,9,... and the 3rd of these is 7.
MATHEMATICA
Block[{a = {1}, nn = 71, s}, s = Range[2, 2 nn + 1]; Do[{AppendTo[a, First@ #1], Set[s, #2]} & @@ TakeDrop[s, If[CompositeQ@ i, 1, {a[[i - 1]]}]], {i, 2, nn}]; a] (* Michael De Vlieger, Sep 25 2017 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Leroy Quet, Feb 18 2005
EXTENSIONS
More terms from Franklin T. Adams-Watters, Nov 22 2006
STATUS
approved