OFFSET
0,2
COMMENTS
If such k exists (for n > 0), then the maximum ratio of k / n is (p + 1)/(p - 1) with p = 2 where p is prime root of corresponding prime power. So a(n) <= 3*n.
Numbers n such that a(n) = 0 are 17, 19, 22, 25, 34, 37, 38, 42, 43, 45, 46, ...
Initial corresponding prime powers are 1, 3, 5, 7, 9, 11, 13, 32, 17, 19, 125, 23, 25, 27, 29, 31, 2048.
EXAMPLE
a(17) = 0 because there is no k such that k^2 - 17^2 = (k + 17)*(k - 17) is a prime power.
a(21) = 22 because 22^2 - 21^2 = 43 and 22 is the least number with this property.
a(27) = 54 because 54^2 - 27^2 = 3^7 and 54 is the only number with this property.
MAPLE
f:= proc(n) local p, k, a, b, r;
if nops(numtheory:-factorset(2*n+1))<=1 then return n+1 fi;
k:= infinity;
for p in numtheory:-factorset(2*n) do
b:= padic:-ordp(2*n, p);
r:= 2*n + p^b;
a:= padic:-ordp(r, p);
if r = p^a then
k:= min(k, (p^a+p^b)/2)
fi
od;
if k = infinity then 0 else k fi
end proc:
map(f, [$0..1000]); # Robert Israel, Mar 15 2018
MATHEMATICA
Table[Boole[n == 0] + Block[{k = n + 1, m = 3 n}, While[Nor[PrimePowerQ[k^2 - n^2], k > m], k++]; If[k > m, 0, k]], {n, 0, 96}] (* Michael De Vlieger, Mar 16 2018 *)
PROG
(PARI) a(n) = if(n==0, 1, for(k=n+1, 3*n, if(isprimepower(k^2-n^2), return(k))); 0)
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Altug Alkan, Mar 14 2018
STATUS
approved