%I #24 Apr 14 2026 00:30:59
%S 0,0,0,0,4,6,10,21,48,197,3854,911,4705,69137,25797,232944,466932,
%T 3110924,4670197,20851430,80081977,987827086,1470388038,6545264485,
%U 35778005903,179227960118,797794938348,79971185783965,17084369697743,227738431773765,1024021410267278
%N Least index k such that prime(k)^2 - n! is again the square of a prime, or 0 if no such prime exists.
%C Upon the observation that 5^2 + 4! = 7^2 and 7^2 + 5! = 13^2, it is natural to ask whether for all n >= 4, there are primes p, q such that p^2 + n! = q^2.
%C This sequence gives the indices (or "primepi" values) of the primes q.
%C At present, it appears to be much easier to compute the primes q = A394632(n) than a(n) = primepi(q) for primes as huge as prime(a(30) ~ 10^15) and beyond.
%F a(n) = A000720(A394632(n)).
%e For n < 4 there are no primes p, q such that p^2 + n! = q^2, since 3^2 - 2^2 = 5 and 5^2 - 3^2 = 16 is already too large.
%e For n = 4 we have 5^2 + 4! = 7^2 and 7 is the 4th prime, so a(4) = 4.
%e For n = 5 we have 7^2 + 5! = 13^2 and 11 is the 6th prime, so a(5) = 6.
%e For n = 6 we have 11^2 + 6! = 29^2 and 29 is the 10th prime, so a(6) = 10.
%e See A394631 for more.
%o (PARI) apply( {A394633(n,f=n!)=n>3&&forprime(p=3,oo,issquare(p^2+f,&q)&& isprime(q)&& return(primepi(q)))}, [0..16])
%o /* or better: */ A394633(n) = primepi(A394632(n))
%Y Cf. A001248 (squares of primes), A000142 (factorial), A000720 (primepi).
%Y See A394632 for prime(a(n)) and further information, A394629 for the number of solutions (p, q).
%K nonn
%O 0,5
%A _M. F. Hasler_, Apr 04 2026
%E More terms from _Daniel Suteu_, Apr 07 2026