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.

A074989 Distance from n to nearest cube.

Original entry on oeis.org

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

Views

Author

Zak Seidov, Oct 02 2002

Keywords

Comments

a(n)=0 when n is a cube; between zeros local maxima are of form 3/2 k(k-1).

Examples

			a(3) = 2 because the nearest cube to 3 is 1 and distance from 3 to 1 is 2.
		

Crossrefs

Cf. A053188 (distance from n to nearest square).

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