Construct a sequence of positive integers
a(n) as follows:
a(0) = 4
- Each term
a(n), other than the first, is the smallest number that satisfies the following:
a(n)is a composite number,
a(n) > a(n-1), and
a(n) + a(k) + 1is a composite number for each
0 <= k < n.
So we start with
a(0) = 4. The next entry,
a(1) must be
9. It can't be
7 since those aren't composite, and it can't be
6+4+1=11 is not composite and
8+4+1=13 is not composite. Finally,
9+4+1=14, which is composite, so
a(1) = 9.
The next entry,
a(2) must be
10, since it's the smallest number larger than
10+4+1=15 both composite.
For the next entry,
13 are both out because they're not composite.
12 is out because
12+4+1=17 which is not composite.
14 is out because
14+4+1=19 which is not composite. Thus,
15 is the next term of the sequence because
15 is composite and
15+10+1=26 are all each composite, so
a(3) = 15.
Here are the first 30 terms in this sequence:
4, 9, 10, 15, 16, 22, 28, 34, 35, 39, 40, 46, 52, 58, 64, 70, 75, 76, 82, 88, 94, 100, 106, 112, 118, 119, 124, 125, 130, 136
This is OEIS A133764.
Given an input integer
n, output the
nth term in this sequence.
- You can choose either 0- or 1-based indexing. Please state which in your submission.
- The input and output can be assumed to fit in your language's native integer type.
- The input and output can be given by any convenient method.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.