login
A074989
Distance from n to nearest cube.
10
0, 0, 1, 2, 3, 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, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
OFFSET
0,4
COMMENTS
a(n)=0 when n is a cube; between zeros local maxima are of form 3/2 k(k-1).
EXAMPLE
a(3) = 2 because the nearest cube to 3 is 1 and distance from 3 to 1 is 2.
MAPLE
A074989 := proc(n) local iscbr ; iroot(n, 3, 'iscbr') ; if iscbr then 0; else iscbr := floor(n^(1/3)) ; min((iscbr+1)^3-n, n-iscbr^3) ; end if; end proc; # R. J. Mathar, Nov 01 2009
MATHEMATICA
dnc[n_]:=Module[{cr=Surd[n, 3]}, Min[n-Floor[cr]^3, Ceiling[cr]^3-n]]; Array[ dnc, 90, 0] (* Harvey P. Dale, Jan 24 2015 *)
PROG
(Haskell)
a074989 0 = 0
a074989 n = min (n - last xs) (head ys - n) where
(xs, ys) = span (< n) a000578_list
-- Reinhard Zumkeller, Nov 28 2011
(Python)
from sympy import integer_nthroot
def A074989(n):
a = integer_nthroot(n, 3)[0]
return min(n-a**3, (a+1)**3-n) # Chai Wah Wu, Mar 31 2021
CROSSREFS
Cf. A053188 (distance from n to nearest square).
Sequence in context: A334234 A291196 A279316 * A307429 A261283 A123548
KEYWORD
nonn
AUTHOR
Zak Seidov, Oct 02 2002
EXTENSIONS
a(0) added and offset changed by Reinhard Zumkeller, Nov 28 2011
STATUS
approved