cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A053188 Distance from n to nearest square.

This page as a plain text file.
%I A053188 #34 Nov 16 2022 09:34:40
%S A053188 0,0,1,1,0,1,2,2,1,0,1,2,3,3,2,1,0,1,2,3,4,4,3,2,1,0,1,2,3,4,5,5,4,3,
%T A053188 2,1,0,1,2,3,4,5,6,6,5,4,3,2,1,0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,1,2,3,
%U A053188 4,5,6,7,8,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1,0,1,2,3,4
%N A053188 Distance from n to nearest square.
%H A053188 Reinhard Zumkeller, <a href="/A053188/b053188.txt">Table of n, a(n) for n = 0..10000</a>
%H A053188 <a href="/index/Di#distance_to_the_nearest">Index entries for sequences related to distance to nearest element of some set</a>
%F A053188 a(n) = |floor(sqrt(n) + 1/2)^2 - n|. - _Ridouane Oudra_, May 01 2019
%F A053188 a(n) <= sqrt(n). - _Charles R Greathouse IV_, Nov 16 2022
%e A053188 a(7)=2 since 9 is the closest square to 7 and |9-7| = 2.
%t A053188 Flatten[Table[Abs[Nearest[Range[0,25]^2,n]-n],{n,0,120}]]  (* _Harvey P. Dale_, Mar 14 2011 *)
%o A053188 (Haskell)
%o A053188 a053188 0 = 0
%o A053188 a053188 n = min (n - last xs) (head ys - n) where
%o A053188    (xs,ys) = span (< n) a000290_list
%o A053188 -- _Reinhard Zumkeller_, Nov 28 2011
%o A053188 (Python)
%o A053188 from math import isqrt
%o A053188 def A053188(n): return abs(((m:=isqrt(n))+int(n-m*(m+1)>=1))**2-n) # _Chai Wah Wu_, Aug 03 2022
%o A053188 (PARI) a(n)=abs(((sqrtint(4*n) + 1)\2)^2 - n) \\ _Charles R Greathouse IV_, Nov 16 2022
%Y A053188 Cf. A053187, A074989, A000290.
%K A053188 easy,nonn
%O A053188 0,7
%A A053188 _Henry Bottomley_, Mar 01 2000