OFFSET
0,5
COMMENTS
Upon the observation that 5^2 + 4! = 25 + 24 = 49 = 7^2, it is natural to ask whether there are primes p, q such that q^2 - p^2 = n! for all n >= 4. This sequence gives the index (or "rank", or "primepi" values) of the corresponding primes p.
FORMULA
EXAMPLE
For 0! = 1, there are no two primes p, q such that p^2 + 1 = q^2, therefore a(0) = 0.
Similarly, for n = 1, 2 and 3, with n! = 1, 2 and 6, there are no two primes p, q such that p^2 + n! = q^2, therefore a(n) = 0 for n = 1, 2 and 3.
For n = 4, we have the primes p = 5 and q = 7 such that 5^2 + 4! = 25 + 24 = 49 = 7^2, so a(4) = primepi(5) = 3.
For n = 5, we have 7^2 + 5! = 13^2, so a(5) = primepi(7) = 4.
For n = 6, we have 11^2 + 6! = 29^2, so a(6) = primepi(11) = 5.
PROG
(PARI) apply( {A394630(n, f=n!)=n>3&&forprime(p=3, oo, issquare(p^2+f, &q)&& isprime(q)&& return(primepi(p)))}, [0..15]) \\ For illustration; better use {A394630(n)=primepi(A394631(n))} with more efficient code given there.
(Sidef) sidef -N 'USE_PRIMECOUNT=1' -E 'for n in (0..30) { n!.diff_of_squares.first_by{.all_prime} || [0, 0] -> last.primepi.print(", ") }' # Daniel Suteu, Apr 09 2026
CROSSREFS
See A394629 for the total number of solutions (p, q): n! = q^2 - p^2.
KEYWORD
nonn
AUTHOR
M. F. Hasler, Apr 04 2026
EXTENSIONS
More terms from Daniel Suteu, Apr 09 2026
STATUS
approved
