OFFSET
1,2
COMMENTS
Initial term a(1)=1 and thereafter:
If n is even and a(n-1) is prime, then a(n) = least prime > a(n-1).
If n is even and a(n-1) is composite and a(n-2) is prime, then a(n) = 1 + greatest prime < a(n-2).
Otherwise, a(n) = a(n-1) + 1.
Every integer will be seen, with many seen twice. Largest first differences will be at prime gaps. Starting at 3, pairs of consecutive primes appear. Interestingly, the values seen once seem to correspond to A093513 except for 2.
EXAMPLE
From 2 we move to 3, it is prime, so go to 5. Next evaluation to 6, having departed from a prime, so go to 3 + 1 = 4. Next eval move to 5, it is prime, so go to 7. Next eval to 8, having departed from a prime, so go to 5 + 1 = 6. Next eval move to 7, it is prime, so go to 11. Next eval move to 12, having departed from a prime, so go to 7 + 1 = 8. Next eval move to 9. Next eval move to 10. Next eval move to 11, it is prime, so go to 13. This example adds the terms 3, 5, 6, 4, 5, 7, 8, 6, 7, 11, 12, 8, 9, 10, 11, 13.
MATHEMATICA
a[1] = 1; a[n_] := a[n] = If[EvenQ[n], If[PrimeQ[a[n-1]], NextPrime[a[n-1] + 1], If[CompositeQ[a[n-1]] && PrimeQ[a[n-2]], 1 + NextPrime[a[n-2], -1], a[n-1] + 1]], a[n-1] + 1]; Array[a, 100] (* Amiram Eldar, Mar 19 2024 *)
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Bill McEachen, Mar 13 2024
STATUS
approved