I know, I know, yet another primes challenge...
A lonely (or isolated) prime is a prime number p
such that p-2
, p+2
, p-4
, p+4
... p-2k
, p+2k
for some k
are all composite. We call such a prime a k
th-times-isolated prime.
For example, a 5th-times-isolated prime is 211
, since all of 201, 203, 205, 207, 209, 213, 215, 217, 219, 221
are composite. (p-2*5=201
, p-2*4=203
, etc.)
Challenge
Given two input integers, n > 3
and k > 0
, output the smallest k
th-times-isolated prime that is strictly larger than n
.
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
.
Examples
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
Rules
- 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.
k
th-times-isolated is also, by definition, ak-1
th,k-2
th, etc. \$\endgroup\$