OFFSET
1,2
COMMENTS
"Cycle" in the definition, means that if no prime is found, go back to the start of the set.
If a set does not contain a prime, the sequence goes into an infinite loop, but it is conjectured that this does not happen since the sets are of increasing length.
The sets (rather intervals) are I_j = [(j^2 + 3*j - 2)/2, j*(j + 5)/2] =[A034856(j), A095998(j)], for j >= 1. For the number of primes in these intervals see A309121. - Wolfdieter Lang, Jul 13 2019
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10000
Rémy Sigrist, PARI program for A307213
EXAMPLE
The first set is {1,2,3}. We look at 1 then 2. 2 is prime, and it is the second number in the set. The next set is {4,5,6,7}. So we jump to the second element, 5. 5 is also prime, so we jump to the second element of the next set, {8,9,10,11,12}, which is 9, etc. If we reach the end of a set without reaching a prime, we loop back to the first element, which is the only way for a(n) < a(n-1) to happen.
MATHEMATICA
Nest[Append[#1, {If[#3 <= Length@ #4, #3, #3 - Length@ #4], If[#2 == #3, {#4[[#3]]}, Join[#4, #4][[#2 ;; #3]]], #4}] & @@ {#1, #2, If[PrimeQ[#3[[#2]] ], #2, #2 + FirstPosition[RotateLeft[#3, #2], _?PrimeQ][[1]] ], #3} & @@ {#1, #2, Range[#3, #3 + #4]} & @@ {#, #[[-1, 1]], 1 + Max@ #[[-1, -1]], Length@ # + 2} &, {{#1, #2[[1 ;; #1]], #2} & @@ {FirstPosition[#, _?PrimeQ][[1]], #}} &@ Range@ 3, 19][[All, 2]] // Flatten (* Michael De Vlieger, Mar 31 2019 *)
PROG
(PARI) See Links section.
CROSSREFS
KEYWORD
nonn
AUTHOR
Christopher Cormier, Mar 28 2019
EXTENSIONS
Edited by N. J. A. Sloane, Jul 13 2019
STATUS
approved