I know, I know, yet another primes challenge...
A lonely (or isolated) prime is a prime number
p such that
p+2k for some
k are all composite. We call such a prime a
For example, a 5th-times-isolated prime is
211, since all of
201, 203, 205, 207, 209, 213, 215, 217, 219, 221 are composite. (
Given two input integers,
n > 3 and
k > 0, output the smallest
kth-times-isolated prime that is strictly larger than
For example, for
k = 5 and any
n in range
4 ... 210, the output should be
211, since that's the smallest 5th-times-isolated prime strictly larger than the input
n=55 k=1 67 n=500 k=1 503 n=2100 k=3 2153 n=2153 k=3 2161 n=14000 k=7 14107 n=14000 k=8 14107
- If applicable, you can assume that the input/output will 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.