OFFSET
1,1
COMMENTS
LINKS
Karl-Heinz Hofmann, Table of n, a(n) for n = 1..10000
Wikipedia, Wilson's theorem.
EXAMPLE
a(1) = 47: 47*6 + 1 = 283 (a prime), 47*6 - 1 = 281 (also a prime), and no k < 6 gives a prime as the result for both formulas.
MATHEMATICA
q[p_] := Module[{k = 1, r}, While[! Or @@ (r = PrimeQ[k*p + {-1, 1}]), k++]; And @@ r]; Select[Prime[Range[900]], q] (* Amiram Eldar, Jan 01 2023 *)
PROG
(Python)
from sympy import sieve, isprime
def leastk(p, plusminus):
k=1
while not isprime(k * p + plusminus): k += 1
return k
print([p for p in sieve[1:1000] if leastk(p, 1) == leastk(p, -1)])
(PARI) isk(p, x) = my(k=1); while (!isprime(k*p+x), k++); k;
isok(p) = if (isprime(p), isk(p, +1) == isk(p, -1)); \\ Michel Marcus, Jan 01 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Karl-Heinz Hofmann, Jan 01 2023
STATUS
approved