

A047972


Distance of nth prime to nearest square.


5



1, 1, 1, 2, 2, 3, 1, 3, 2, 4, 5, 1, 5, 6, 2, 4, 5, 3, 3, 7, 8, 2, 2, 8, 3, 1, 3, 7, 9, 8, 6, 10, 7, 5, 5, 7, 12, 6, 2, 4, 10, 12, 5, 3, 1, 3, 14, 2, 2, 4, 8, 14, 15, 5, 1, 7, 13, 15, 12, 8, 6, 4, 17, 13, 11, 7, 7, 13, 14, 12, 8, 2, 6, 12, 18, 17, 11, 3, 1, 9, 19, 20, 10, 8, 2, 2, 8, 16, 20, 21
(list;
graph;
refs;
listen;
history;
text;
internal format)



OFFSET

1,4


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. 139 = 4, 1613 is 3, so the distance is 3.


MATHEMATICA

a[n_] := (p = Prime[n]; ns = p+1; While[ !IntegerQ[ Sqrt[ns++]]]; ps = p1; While[ !IntegerQ[ Sqrt[ps]]]; Min[ nsp1, pps1]); Table[a[n], {n, 1, 90}] (* JeanFranç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 *)


PROG

(Python)
from sympy import integer_nthroot, prime
def A047972(n):
p = prime(n)
a = integer_nthroot(p, 2)[0]
return min(pa**2, (a+1)**2p) # Chai Wah Wu, Apr 03 2021


CROSSREFS

Cf. A047973.
Sequence in context: A088904 A241568 A335017 * A004595 A071681 A135621
Adjacent sequences: A047969 A047970 A047971 * A047973 A047974 A047975


KEYWORD

easy,nonn,nice


AUTHOR

Enoch Haga, Dec 11 1999


STATUS

approved



