Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #26 Aug 01 2024 18:07:14
%S 0,2,2,1,1,9,1,81,729,225,324,39169,82944,176400,215296,3444736,
%T 26167684,114349225,255004929,1158920361,11638526761,42128246889,
%U 191052974116,97216010329,2430400258225,1553580508516,4666092737476,565986718738441,2137864362693921,5112360635841936
%N Least number k >= 0 such that n! + k is a perfect power.
%C The only n <= 805 where n! + a(n) is not a square is 3. - _Robert Israel_, Aug 01 2024
%H Robert Israel, <a href="/A240939/b240939.txt">Table of n, a(n) for n = 1..805</a>
%p f:= proc(n) local v,m,p,r;
%p m:= infinity;
%p v:= n!;
%p p:= 1;
%p do
%p p:= nextprime(p);
%p if 2^p >= m+v then break fi;
%p r:= ceil(v^(1/p))^p - v;
%p if r < m then m:= r fi;
%p od;
%p m
%p end proc:
%p map(f, [$1..50]);
%t nextPerfectPower[n_] := Min@ Table[(Floor[n^(1/k)] + 1)^k, {k, 2, 1 + Floor@ Log2@ n}]; f[n_] := nextPerfectPower[n!] - n!; f[1] = 0; Array[f, 30] (* _Robert G. Wilson v_, Aug 04 2014 *)
%o (PARI)
%o a(n)=for(k=0,10^10,s=n!+k;if(ispower(s)||s==1,return(k)))
%o n=1;while(n<50,print1(a(n),", ");n++)
%o (PARI)
%o a(n)=for(k=1,n!,if(2^k>n!,kk=k;break));if(kk==1,return(0));L=List([]);for(i=2,kk,listinsert(L,ceil(n!^(1/i))^i-n!,1));listsort(L);L[1]
%o vector(40, n, a(n)) \\ faster program
%Y Cf. A068869, A240937.
%K nonn
%O 1,2
%A _Derek Orr_, Aug 03 2014
%E a(18) onward from _Robert G. Wilson v_, Aug 04 2014