A074989 Distance from n to nearest cube.
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
Keywords
Examples
a(3) = 2 because the nearest cube to 3 is 1 and distance from 3 to 1 is 2.
Links
Programs
-
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
-
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 *)
-
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
Extensions
a(0) added and offset changed by Reinhard Zumkeller, Nov 28 2011
Comments