user
Suppose you have a sequence of integers, starting with 1. Each integer that gets added to the sequence must be lexicographically later, and must have the property that when added, there is no subsequence that will sum to a prime number.

Note

for the purposes of this task, "lexicographically later" means "greater than" - see the Mathematical discussion of ordering link below.

E.G.

```
   Sequence starts with: (1)
   testing integers...
   1  - is not lexicographically later
   2  - 2 + 1 is 3, a prime
   3  - is prime ( a sum can be of a single element )
   4  - 4 + 1 is 5, a prime
   5  - is prime
   6  - 6 + 1 is 7, a prime
   7  - is prime 
   8  - 8 is later than 1, is not prime and 8 + 1 is not prime, so 8 is added to the sequence
   and so on...

```

There are variations of this sequence that have some further constraints.

* Same premise except that each added integer must also be odd.
* Same premise except that each added integer must also be even.

Task

Find the first **eight** elements of each variation, starting with **1**, where each added element is:

* Lexicographically later, and yields no non-prime subsequence sum.
* Lexicographically later, yields no non-prime subsequence sum, and is odd.
* Lexicographically later, yields no non-prime subsequence sum, and is even.

Stretch

The numbers grow quite large very quickly. Find the first **ten** elements of each sequence, with an approximate elapsed time.

See also

* OEIS A052349 - Lexicographically earliest sequence of distinct positive integers such that no subsequence sums to a prime * OEIS A128687 - Smallest odd nonprime such that every subset sums to a nonprime * OEIS A128688 - a(1)=1. For n>1, a(n) is the smallest even number such that every subset sums to a nonprime * Mathematical discussion of Ordering
assistant
This version is multi-threaded to take advantage of multicore processors. When run on a Ryzen 5950 16 core processor, it takes a little under 1 second total to produce the first 8 elements of all three sequences. Stepping up to 10 elements of each takes just over 31 minutes total. :-( The timing will scale inversely with the number of cores available.

Attempt This Online! (8 elements only)

```
say "Sequence, starting with 1, then:";

for '', (*), 'odd ', (* % 2), 'even ', (* %% 2) -> $label, $filter {
    my @check = 0, 1;
    my @seq = 1, |lazy gather loop {
        state $last = 1;
        take $last = ($last^..Inf).grep($filter).hyper.grep({ none (@check.grep({.defined}) »+» $_)».is-prime })[0];
        @check.append: @check »+» $last;
    }

    say "\nlexicographically  earliest {$label}integer such that no subsequence sums to a prime:\n", 
    @seq[^10];
}

```

Output:

```
Sequence, starting with 1, then:

lexicographically earliest integer such that no subsequence sums to a prime:
(1 8 24 25 86 1260 1890 14136 197400 10467660)

lexicographically earliest odd integer such that no subsequence sums to a prime:
(1 9 15 39 105 731 2805 59535 2658795 78060135)

lexicographically earliest even integer such that no subsequence sums to a prime:
(1 8 24 86 90 780 5940 52350 278460 40768260)
```