OFFSET
1,4
COMMENTS
Conjecture: a(n) < sqrt(prime(n)) and lim_{n->infinity} a(n)/sqrt(prime(n)) = 1, where prime(n) is the n-th prime. - Ya-Ping Lu, Nov 29 2021
LINKS
T. D. Noe, Table of n, a(n) for n = 1..1000
FORMULA
For each prime, find the closest square (preceding or succeeding); subtract, take absolute value.
EXAMPLE
For 13, 9 is the preceding square, 16 is the succeeding. 13-9 = 4, 16-13 is 3, so the distance is 3.
MATHEMATICA
a[n_] := (p = Prime[n]; ns = p+1; While[ !IntegerQ[ Sqrt[ns++]]]; ps = p-1; While[ !IntegerQ[ Sqrt[ps--]]]; Min[ ns-p-1, p-ps-1]); Table[a[n], {n, 1, 90}] (* Jean-François Alcover, Nov 18 2011 *)
Table[Apply[Min, Abs[p - Through[{Floor, Ceiling}[Sqrt[p]]]^2]], {p, Prime[Range[90]]}] (* Jan Mangaldan, May 07 2014 *)
Min[Abs[#-Through[{Floor, Ceiling}[Sqrt[#]]]^2]]&/@Prime[Range[100]] (* More concise version of program immediately above *) (* Harvey P. Dale, Dec 04 2019 *)
Rest[Table[With[{s=Floor[Sqrt[p]]}, Abs[p-Nearest[Range[s-2, s+2]^2, p]]], {p, Prime[ Range[ 100]]}]//Flatten] (* Harvey P. Dale, Apr 27 2022 *)
PROG
(Python)
from sympy import integer_nthroot, prime
def A047972(n):
p = prime(n)
a = integer_nthroot(p, 2)[0]
return min(p-a**2, (a+1)**2-p) # Chai Wah Wu, Apr 03 2021
CROSSREFS
KEYWORD
easy,nonn,nice
AUTHOR
Enoch Haga, Dec 11 1999
STATUS
approved