OFFSET
0,6
COMMENTS
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
LINKS
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
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
