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.

Showing 1-9 of 9 results.

A053188 Distance from n to nearest square.

Original entry on oeis.org

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
Offset: 0

Views

Author

Henry Bottomley, Mar 01 2000

Keywords

Examples

			a(7)=2 since 9 is the closest square to 7 and |9-7| = 2.
		

Crossrefs

Programs

  • 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
    
  • Mathematica
    Flatten[Table[Abs[Nearest[Range[0,25]^2,n]-n],{n,0,120}]]  (* Harvey P. Dale, Mar 14 2011 *)
  • PARI
    a(n)=abs(((sqrtint(4*n) + 1)\2)^2 - n) \\ Charles R Greathouse IV, Nov 16 2022
  • 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
    

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

A201053 Nearest cube.

Original entry on oeis.org

0, 1, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
Offset: 0

Views

Author

Reinhard Zumkeller, Nov 28 2011

Keywords

Comments

a(n) = if n-A048763(n) < A048762(n)-n then A048762(n) else A048763(n);
apart from 0, k^3 occurs 3*n^2+1 times, cf. A056107.

Crossrefs

Cf. A061023, A074989, A053187 (nearest square), A000578.

Programs

  • Haskell
    a201053 n = a201053_list !! n
    a201053_list = 0 : concatMap (\x -> replicate (a056107 x) (x ^ 3)) [1..]
    
  • Maple
    seq(k^3 $ (3*k^2+1), k=0..10); # Robert Israel, Jan 03 2017
  • Mathematica
    Module[{nn=70,c},c=Range[0,Ceiling[Surd[nn,3]]]^3;Flatten[Array[ Nearest[ c,#]&,nn,0]]] (* Harvey P. Dale, May 27 2014 *)
  • Python
    from sympy import integer_nthroot
    def A201053(n):
        a = integer_nthroot(n,3)[0]
        return a**3 if 2*n < a**3+(a+1)**3 else (a+1)**3 # Chai Wah Wu, Mar 31 2021

Formula

G.f.: (1-x)^(-1)*Sum_{k>=0} (3*k^2+3*k+1)*x^((k+1)*(k^2+k/2+1)). - Robert Israel, Jan 03 2017
Sum_{n>=1} 1/a(n)^2 = Pi^4/30 + Pi^6/945. - Amiram Eldar, Aug 15 2022

A296239 a(n) = distance from n to nearest Fibonacci number.

Original entry on oeis.org

0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 2, 2, 1, 0, 1, 2, 3, 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, 8, 9, 10, 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, 16, 15, 14, 13, 12, 11, 10, 9
Offset: 0

Views

Author

Rémy Sigrist, Dec 09 2017

Keywords

Comments

The Fibonacci numbers correspond to sequence A000045.
This sequence is analogous to:
- A051699 (distance to nearest prime),
- A053188 (distance to nearest square),
- A053646 (distance to nearest power of 2),
- A053615 (distance to nearest oblong number),
- A053616 (distance to nearest triangular number),
- A061670 (distance to nearest power),
- A074989 (distance to nearest cube),
- A081134 (distance to nearest power of 3),
The local maxima of the sequence correspond to positive terms of A004695.
a(n) = 0 iff n = A000045(k) for some k >= 0.
a(n) = 1 iff n = A061489(k) for some k > 4.
For any n >= 0, abs(a(n+1) - a(n)) <= 1.
For any n > 0, a(n) < n, and a^k(n) = 0 for some k > 0 (where a^k denotes the k-th iterate of a); k equals A105446(n) for n = 1..80 (and possibly more values).
a(n) > max(a(n-1), a(n+1)) iff n = A001076(k) for some k > 1.

Examples

			For n = 42:
- A000045(9) = 34 <= 42 <= 55 = A000045(10),
- a(42) = min(42 - 34, 55 - 42) = min(8, 13) = 8.
		

Crossrefs

Programs

  • Mathematica
    fibPi[n_] := 1 + Floor[ Log[ GoldenRatio, 1 + n*Sqrt@5]]; f[n_] := Block[{m = fibPi@ n}, Min[n - Fibonacci[m -1], Fibonacci[m] - n]]; Array[f, 81, 0] (* Robert G. Wilson v, Dec 11 2017 *)
    With[{nn=80,fibs=Fibonacci[Range[0,20]]},Table[Abs[n-Nearest[fibs,n]][[1]],{n,0,nn}]] (* Harvey P. Dale, Jul 02 2022 *)
  • PARI
    a(n) = for (i=1, oo, if (n<=fibonacci(i), return (min(n-fibonacci(i-1), fibonacci(i)-n))))

Formula

a(n) = abs(n - Fibonacci(floor(log(sqrt(20)*n)/log((1 + sqrt(5))/2)-1))). - Jon E. Schoenfield, Dec 14 2017

A154840 Distance to nearest cube different from n.

Original entry on oeis.org

1, 1, 1, 2, 3, 3, 2, 1, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 19, 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, 37, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
Offset: 0

Views

Author

R. J. Mathar, Nov 01 2009

Keywords

Comments

Equals A074989(n) if this is not zero, else 1+A055400(n-1), the distance to the nearest cube < n.

Examples

			a(8)=7, because the two cubes below and above 8 are 1^3=1 and 3^3=27, and the distance to 1 is smaller, namely 8-1=7.
		

Crossrefs

Programs

  • Maple
    distNearstDiffCub := proc(n) local iscbr ; iroot(n,3,'iscbr') ; if iscbr then 1+A055400(n-1); else A074989(n) ; end if; end proc;
  • Mathematica
    dnc[n_]:=Module[{c=Surd[n,3]},If[IntegerQ[c],n-(c-1)^3,Min[n-Floor[ c]^3, Ceiling[c]^3-n]]]; Array[dnc,90,0] (* Harvey P. Dale, Mar 30 2019 *)

A163497 Numbers n with following property: let c = nearest cube to n that is different from n and let p = nearest prime to n that is different from n. Then |n-c| = |n-p|.

Original entry on oeis.org

2, 25, 28, 119, 126, 340, 345, 728, 731, 1329, 1346, 2188, 2200, 3374, 3382, 4911, 4916, 6858, 6861, 9259, 9269, 12165, 12182, 15622, 15627, 19682, 19685, 24384, 24390, 29790, 29797, 35935, 35944, 42869, 42887, 50652, 50662, 59300, 59326
Offset: 1

Views

Author

Gaurav Kumar, Jul 29 2009

Keywords

Comments

With the exception of 2 those k where A051699(k) = A074989(k) (same distance to nearest prime and to nearest cube). - R. J. Mathar, Aug 08 2009

Examples

			a(1) = 2 since 2 lies between 1 (cube) and 3 (prime);
a(2) = 28 since 28 lies between 27 (cube) and 29 (prime).
		

Crossrefs

Cf. A154840.

Programs

  • Maple
    A163497 := proc(n) option remember ; local a; if n = 1 then 2; else for a from procname(n-1)+1 do if A051699(a) = A074989(a) then return a; end if; end do ; end if; end proc: # R. J. Mathar, Nov 01 2009

Extensions

Edited by Zak Seidov, Aug 01 2009
Further edited by N. J. A. Sloane, Oct 31 2009

A301626 Square array T(n, k) read by antidiagonals, n >= 0 and k >= 0: T(n, k) = square of the distance from n + k*i to nearest cube of a Gaussian integer (where i denotes the root of -1 with positive imaginary part).

Original entry on oeis.org

0, 0, 0, 1, 1, 1, 4, 1, 1, 4, 8, 2, 0, 2, 8, 9, 5, 1, 1, 5, 9, 4, 10, 4, 2, 4, 10, 4, 1, 5, 9, 5, 5, 9, 5, 1, 0, 2, 8, 10, 8, 10, 8, 2, 0, 1, 1, 5, 13, 13, 13, 13, 5, 1, 1, 4, 2, 4, 10, 20, 18, 20, 10, 4, 2, 4, 4, 2, 4, 9, 17, 25, 25, 17, 9, 4, 2, 4, 5, 1, 1
Offset: 0

Views

Author

Rémy Sigrist, Mar 24 2018

Keywords

Comments

The distance between two Gaussian integers is not necessarily integer, hence the use of the square of the distance.
This sequence is a complex variant of A074989.
See A301636 for the square array dealing with squares of Gaussian integers.

Examples

			Square array begins:
  n\k|    0    1    2    3    4    5    6    7    8    9   10
  ---+-------------------------------------------------------
    0|    0    0    1    4    8    9    4    1    0    1    4  -->  A301639
    1|    0    1    1    2    5   10    5    2    1    2    2
    2|    1    1    0    1    4    9    8    5    4    4    1
    3|    4    2    1    2    5   10   13   10    9    5    2
    4|    8    5    4    5    8   13   20   17   13    8    5
    5|    9   10    9   10   13   18   25   25   18   13   10
    6|    4    5    8   13   20   25   32   32   25   20   17
    7|    1    2    5   10   17   25   32   41   34   29   26
    8|    0    1    4    9   13   18   25   34   45   40   37
    9|    1    2    4    5    8   13   20   29   40   53   50
   10|    4    2    1    2    5   10   17   26   37   50   65
		

Crossrefs

Cf. A000578, A074989, A301636, A301639 (first row/column).

Programs

  • PARI
    See Links section.

Formula

T(n, k) = T(k, n).
T(n, 0) <= A074989(n)^2.
T(n, 0) = 0 iff n is a cube (A000578).
T(n, k) = 0 iff n + k*i = z^3 for some Gaussian integer z.

A301639 a(n) = square of the distance from n to nearest cube of a Gaussian integer.

Original entry on oeis.org

0, 0, 1, 4, 8, 9, 4, 1, 0, 1, 4, 4, 5, 8, 13, 20, 29, 40, 53, 64, 49, 36, 25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 130, 117, 106, 97, 90, 85, 82, 81, 82, 85, 90, 97, 106, 117, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25
Offset: 0

Views

Author

Rémy Sigrist, Mar 25 2018

Keywords

Comments

The distance between two Gaussian integers is not necessarily integer, hence the use of the square of the distance.
This sequence is a variant of A074989: here we minimize norm(n - z^3) where z runs through every Gaussian integers, there we minimize abs(n - m^3) where m runs through every integers.

Examples

			For n = 4: the nearest Gaussian cubes to 4 are 2 + 2*i and 2 - 2*i, hence a(4) = (4-2)^2 + 2^2 = 8.
		

Crossrefs

Formula

a(n) = A301626(n, 0).
a(n) <= A074989(n)^2.

A342873 Numbers whose distance to the nearest cube equals the distance to the nearest product of 3 consecutive integers (three-dimensional oblong).

Original entry on oeis.org

0, 7, 16, 62, 92, 213, 276, 508, 616, 995, 1160, 1722, 1956, 2737, 3052, 4088, 4496, 5823, 6336, 7990, 8620, 10637, 11396, 13812, 14712, 17563, 18616, 21938, 23156, 26985, 28380, 32752, 34336, 39287, 41072, 46638, 48636, 54853, 57076, 63980, 66440, 74067
Offset: 1

Views

Author

Lamine Ngom, Mar 28 2021

Keywords

Comments

That is, numbers k such that A074989(k) = A342872(k).
They form 2 partitions:
7, 62, 213, ... = 8*k^3 - k = k*A157914(k).
0, 16, 92, ... = 8*k^3 + 6*k^2 + 2*k = 2*k*A033951(k).

Crossrefs

Programs

  • Python
    def aupto(limit):
      cubes = [k**3 for k in range(int((limit+1)**1/3)+2)]
      proms = [k*(k+1)*(k+2) for k in range(int((limit+1)**1/3)+1)]
      A074989 = [min(abs(n-c) for c in cubes) for n in range(limit+1)]
      A342872 = [min(abs(n-p) for p in proms) for n in range(limit+1)]
      return [m for m in range(limit+1) if A074989[m] == A342872[m]]
    print(aupto(10**4)) # Michael S. Branicky, Mar 28 2021

A289642 Number of 2-digit numbers whose digits add up to n.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1
Offset: 1

Views

Author

Miquel Cerda, Jul 09 2017

Keywords

Comments

The 2-digit numbers distributed according to the sum of their digits n.
Symmetrical sequence; a(n) = a(19 - n).

Examples

			n(5) = 5 because there are 5 numbers whose digits sum = 5 (14, 23, 32, 41, 50).
		

Crossrefs

Cf. A071817 (3-digit numbers), A090579 (4-digit numbers), A090580 (5-digit numbers), A090581 (6-digit numbers), A278969 (7-digit numbers), A278971 (8-digit numbers), A289354 (9-digit numbers), A053188, A074989, A004739, A066635, A154840, A249121.

Formula

G.f.: (1 - x^10)*(x - x^10)/(1 - x)^2.
a(n) = (19-abs(n-9)-abs(n-10))/2 for n=1..18. - Wesley Ivan Hurt, Jul 09 2017
Showing 1-9 of 9 results.