# Greetings from The On-Line Encyclopedia of Integer Sequences! http://oeis.org/ Search: id:a047972 Showing 1-1 of 1 %I A047972 #36 Apr 27 2022 19:06:00 %S A047972 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, %T A047972 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, %U A047972 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 %N A047972 Distance of n-th prime to nearest square. %C A047972 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 %H A047972 T. D. Noe, Table of n, a(n) for n = 1..1000 %F A047972 For each prime, find the closest square (preceding or succeeding); subtract, take absolute value. %e A047972 For 13, 9 is the preceding square, 16 is the succeeding. 13-9 = 4, 16-13 is 3, so the distance is 3. %t A047972 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 *) %t A047972 Table[Apply[Min, Abs[p - Through[{Floor, Ceiling}[Sqrt[p]]]^2]], {p, Prime[Range[90]]}] (* _Jan Mangaldan_, May 07 2014 *) %t A047972 Min[Abs[#-Through[{Floor,Ceiling}[Sqrt[#]]]^2]]&/@Prime[Range[100]] (* More concise version of program immediately above *) (* _Harvey P. Dale_, Dec 04 2019 *) %t A047972 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 *) %o A047972 (Python) %o A047972 from sympy import integer_nthroot, prime %o A047972 def A047972(n): %o A047972 p = prime(n) %o A047972 a = integer_nthroot(p,2)[0] %o A047972 return min(p-a**2,(a+1)**2-p) # _Chai Wah Wu_, Apr 03 2021 %Y A047972 Cf. A047973. %K A047972 easy,nonn,nice %O A047972 1,4 %A A047972 _Enoch Haga_, Dec 11 1999 # Content is available under The OEIS End-User License Agreement: http://oeis.org/LICENSE