login
A393254
Smallest k such that both n! + k and n! + k + 2 are primes.
1
2, 2, 1, 5, 5, 17, 89, 59, 107, 71, 167, 17, 191, 347, 1667, 1457, 197, 281, 101, 137, 137, 149, 989, 4049, 4157, 1019, 311, 5519, 101, 2201, 7739, 6161, 6131, 3257, 9767, 13757, 9257, 2549, 4601, 7571, 13679, 6131, 6197, 7919, 599, 5279, 9929, 1061, 101, 4637, 1931, 14657
OFFSET
0,1
COMMENTS
This sequence represents the distance from n! to the first twin prime pair following it.
Because n! acts as a strong Mertens filter (being divisible by all primes <= n), the local density of primes immediately following n! is significantly higher than in random intervals of similar magnitude.
Empirical observation by the author suggests that a(n) < n^3 for all n >= 2, which implies a highly compact bound for the first twin prime pair after a factorial. This sequence is the twin-prime analog to A037153.
LINKS
FORMULA
a(n) = min { k >= 0 | n! + k is prime and n! + k + 2 is prime }.
EXAMPLE
For n = 3, 3! = 6. For k = 1, 2, 3, 4, the pairs (6+k, 6+k+2) are (7,9), (8,10), (9,11), and (10,12), none of which are twin primes. For k = 5, (11, 13) are twin primes, so a(3) = 5.
For n = 4, 4! = 24. For k = 1, 2, 3, 4, the numbers 24+k (25, 26, 27, 28) are all composite. For k = 5, (29, 31) are twin primes, so a(4) = 5.
MAPLE
f:= proc(n) local N, k;
N:= n!;
for k from 5 by 6 do
if isprime(N+k) and isprime(N+k+2) then return k fi
od
end proc:
f(0):= 2: f(1):= 2: f(2):= 1:
map(f, [$0..60]); # Robert Israel, Mar 08 2026
MATHEMATICA
a[n_]:=Module[{k=0}, While[!PrimeQ[n!+k]||!PrimeQ[n!+k+2], k++]; k]; Array[a, 52, 0] (* Stefano Spezia, Mar 08 2026 *)
PROG
(Python)
from sympy import isprime, factorial
def A393254(n):
fact_n = factorial(n)
k = 0
while True:
if isprime(fact_n + k) and isprime(fact_n + k + 2):
return k
k += 1
print([A393254(n) for n in range(0, 16)])
(PARI) a(n) = my(k=0, f=n!); while (!(ispseudoprime(f+k) && ispseudoprime(f+k+2)), k++); k; \\ Michel Marcus, Mar 08 2026
CROSSREFS
Sequence in context: A133611 A010094 A019710 * A118806 A328646 A171670
KEYWORD
nonn
AUTHOR
Fan Yu, Mar 08 2026
EXTENSIONS
More terms from Michel Marcus, Mar 08 2026
STATUS
approved