login
A394629
Number of pairs of primes (p, q) such that n! = q^2 - p^2.
6
0, 0, 0, 0, 1, 3, 3, 3, 4, 2, 2, 2, 3, 3, 4, 5, 2, 5, 3, 6, 4, 4, 5, 11, 9, 9, 5, 6, 8, 10, 12, 13, 18, 25, 20, 14, 9, 26, 14, 28, 12, 44, 39, 60, 47, 61, 60, 147, 95, 85, 105, 88, 79, 167, 172, 150, 168, 149, 136, 271, 261, 513, 502, 481, 439, 463, 447, 808, 705, 738, 778
OFFSET
0,6
COMMENTS
See A394631 for the smallest p and A394632 for the corresponding q.
We have n! = q^2 - p^2 = (q - p)*(q + p) so that q, p = |n!/d +- d|/2 for some divisor d of n!. The number of these divisors grows quite fast (e.g., 10^8 for n=40), see A027423 and A138196 for the number of decompositions as difference of squares.
It appears that the growth of these numbers is such that it compensates for the decreasing density of primes, leading to a growing number of solutions as n grows.
It also appears that in general there are less solutions for even n than for odd n. We have a(n) < a(n-1) for n = 9, 16, 18, 20, 24, 26, 34, 35, 36, 38, 40, 42, 44, 46, 48, 49, 51, 52, 55, 57, 58, 60, ...
There are at most 2^(primepi(n)) divisors d such that gcd(n!/d, d) = 2. To ensure no double counting let 2^v | d where v + 1 is the 2-adic valuation of n!. - David A. Corneth, Apr 09 2026
Otherwise said, we have q, p = |f/d +- d| where f = n!/4 and d has either all or none of the prime factors of f, for any given prime. - M. F. Hasler, Apr 11 2026
EXAMPLE
For n < 4 there can't be any such p, q because 3^2 - 2^2 = 5 and 5^2 - 3^2 = 16 is already larger than 3! = 6, so a(n) = 0.
For n = 4 we have 7^2 - 5^2 = 49 - 25 = 24 = 4!, so (p, q) = (5, 7) is the only solution, so a(4) = 1.
For n = 5 we have 5! = 120 = 13^2 - 7^2 = 17^2 - 13^2 = 31^2 - 29^2, so we have a(5) = 3 solutions (7, 13), (13, 17) and (29, 31).
PROG
(PARI) apply( {A394629(n)=my(f=if(n>3, factor(n=n!\4)[2..-1, ]~), d); sum(m=0, 2^#f-1, d=if(m, factorback(vecextract(f, m)~), 1); ispseudoprime(abs(n\d-d))&& ispseudoprime(n\d+d))}, [0..30])
(PARI) a(n)=if(n<4, return(0)); my(N=n!); sumdiv(vecprod(primes([3, n])), d, my(U=2*gcd(d^n, N)); ispseudoprime(abs(N/U-U)/2)&&ispseudoprime((N/U+U)/2)); \\ Daniel Suteu, Apr 10 2026
(SageMath) # see Dony link.
CROSSREFS
Cf. A027423 (number of divisors of n!), A394630 - A394633 (smallest p and q and their indices within the primes).
Cf. A138196 (similar with p, q not necessarily prime).
Sequence in context: A357261 A010265 A239963 * A084501 A198020 A098037
KEYWORD
nonn
AUTHOR
M. F. Hasler, Apr 05 2026
EXTENSIONS
a(30)-a(36) from Daniel Suteu, Apr 07 2026
a(41)-a(61) from David A. Corneth, Apr 08 2026
a(62)-a(70) from Daniel Suteu, Apr 09 2026
STATUS
approved