login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A053188 Distance from n to nearest square. 20
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, 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, 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 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,7
LINKS
FORMULA
a(n) = |floor(sqrt(n) + 1/2)^2 - n|. - Ridouane Oudra, May 01 2019
a(n) <= sqrt(n). - Charles R Greathouse IV, Nov 16 2022
EXAMPLE
a(7)=2 since 9 is the closest square to 7 and |9-7| = 2.
MATHEMATICA
Flatten[Table[Abs[Nearest[Range[0, 25]^2, n]-n], {n, 0, 120}]] (* Harvey P. Dale, Mar 14 2011 *)
PROG
(Haskell)
a053188 0 = 0
a053188 n = min (n - last xs) (head ys - n) where
(xs, ys) = span (< n) a000290_list
-- Reinhard Zumkeller, Nov 28 2011
(Python)
from math import isqrt
def A053188(n): return abs(((m:=isqrt(n))+int(n-m*(m+1)>=1))**2-n) # Chai Wah Wu, Aug 03 2022
(PARI) a(n)=abs(((sqrtint(4*n) + 1)\2)^2 - n) \\ Charles R Greathouse IV, Nov 16 2022
CROSSREFS
Sequence in context: A368494 A061926 A180835 * A109389 A098884 A297964
KEYWORD
easy,nonn
AUTHOR
Henry Bottomley, Mar 01 2000
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 29 18:29 EDT 2024. Contains 372114 sequences. (Running on oeis4.)