%I #24 Jul 27 2020 04:45:11
%S 0,0,0,1,2,1,0,0,2,0,3,1,3,0,2,0,3,1,0,0,2,0,3,0,3,0,0,0,4,1,0,0,0,0,
%T 4,0,4,0,2,0,0,1,4,0,2,0,4,0,0,0,0,0,3,0,4,0,0,0,0,1,0,0,0,0,4,0,3,0,
%U 2,0,0,1,3,0,0,0,4,0,0,0,2,0,4,0,4,0,0,0,0,0,0,0,0,0,3
%N Largest number k > 0 such that n + k! and n - k! are both prime, or 0 if no such k exists.
%C If k > n, n - k! is surely negative and, therefore, not prime.
%C a(n) < A020639(n). - _Robert Israel_, Aug 10 2014
%H Robert Israel, <a href="/A241425/b241425.txt">Table of n, a(n) for n = 1..10000</a>
%p a:= proc(n)
%p local k;
%p for k from min(numtheory:-factorset(n))-1 to 1 by -1 do
%p if n > k! and isprime(n+k!) and isprime(n-k!) then return(k) fi
%p od:
%p 0
%p end proc:
%p a(1):= 0:
%p seq(a(n),n=1..100); # _Robert Israel_, Aug 10 2014
%t a[n_] := Module[{k}, For[k = FactorInteger[n][[1, 1]], k >= 1, k--, If[n > k! && PrimeQ[n + k!] && PrimeQ[n - k!], Return[k]]]; 0];
%t a[1] = 0;
%t Array[a, 100] (* _Jean-François Alcover_, Jul 27 2020, after Maple *)
%o (PARI)
%o a(n)=forstep(k=n,1,-1,if(ispseudoprime(n+k!)&&ispseudoprime(n-k!),return(k)))
%o n=1;while(n<150,print1(a(n),", ");n++)
%Y Cf. A020639, A245716, A241423, A241424.
%K nonn
%O 1,5
%A _Derek Orr_, Aug 08 2014