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-10 of 19 results. Next

A074378 Even triangular numbers halved.

Original entry on oeis.org

0, 3, 5, 14, 18, 33, 39, 60, 68, 95, 105, 138, 150, 189, 203, 248, 264, 315, 333, 390, 410, 473, 495, 564, 588, 663, 689, 770, 798, 885, 915, 1008, 1040, 1139, 1173, 1278, 1314, 1425, 1463, 1580, 1620, 1743, 1785, 1914, 1958, 2093, 2139, 2280, 2328, 2475
Offset: 0

Views

Author

W. Neville Holmes, Sep 04 2002

Keywords

Comments

Set of integers k such that k + (1 + 2 + 3 + 4 + ... + x) = 3*k, where x is sufficiently large. For example, 203 is a term because 203 + (1 + 2 + 3 + 4 + ... +28) = 609 and 609 = 3*203. - Gil Broussard, Sep 01 2008
Set of all m such that 16*m+1 is a perfect square. - Gary Detlefs, Feb 21 2010
Integers of the form Sum_{k=0..n} k/2. - Arkadiusz Wesolowski, Feb 07 2012
Numbers of the form h*(4*h + 1) for h = 0, -1, 1, -2, 2, -3, 3, ... - Bruno Berselli, Feb 26 2018
Numbers whose distance to nearest square equals their distance to nearest oblong; that is, numbers k such that A053188(k) = A053615(k). - Lamine Ngom, Oct 27 2020
The sequence terms are the exponents in the expansion of Product_{n >= 1} (1 - q^(8*n))*(1 + q^(8*n-3))*(1 + q^(8*n-5)) = 1 + q^3 + q^5 + q^14 + q^18 + .... - Peter Bala, Dec 30 2024

Crossrefs

Cf. A010709, A047522. [Vincenzo Librandi, Feb 14 2009]
Cf. A266883 (numbers n such that 16*n-15 is a square).

Programs

  • Magma
    f:=func; [0] cat [f(n*m): m in [-1,1], n in [1..25]]; // Bruno Berselli, Nov 13 2012
  • Maple
    a:=n->(2*n+1)*floor((n+1)/2): seq(a(n),n=0..50); # Muniru A Asiru, Feb 01 2019
  • Mathematica
    1/2 * Select[PolygonalNumber@ Range[0, 100], EvenQ] (* Michael De Vlieger, Jun 01 2017, Version 10.4 *)
    Select[Accumulate[Range[0,100]],EvenQ]/2 (* Harvey P. Dale, Feb 15 2025 *)
  • PARI
    a(n)=(2*n+1)*(n-n\2)
    

Formula

Sum_{n>=0} q^a(n) = (Prod_{n>0} (1-q^n))*(Sum_{n>=0} A035294(n)*q^n).
a(n) = n*(n + 1)/4 where n*(n + 1)/2 is even.
G.f.: x*(3 + 2*x + 3*x^2)/((1 - x)*(1 - x^2)^2).
From Benoit Jubin, Feb 05 2009: (Start)
a(n) = (2*n + 1)*floor((n + 1)/2).
a(2*k) = k*(4*k+1); a(2*k+1) = (k+1)*(4*k+3). (End)
a(2*n) = A007742(n), a(2*n-1) = A033991(n). - Arkadiusz Wesolowski, Jul 20 2012
a(n) = (4*n + 1 - (-1)^n)*(4*n + 3 - (-1)^n)/4^2. - Peter Bala, Jan 21 2019
a(n) = (2*n+1)*(n+1)*(1+(-1)^(n+1))/4 + (2*n+1)*(n)*(1+(-1)^n)/4. - Eric Simon Jacob, Jan 16 2020
From Amiram Eldar, Jul 03 2020: (Start)
Sum_{n>=1} 1/a(n) = 4 - Pi (A153799).
Sum_{n>=1} (-1)^(n+1)/a(n) = 6*log(2) - 4 (See A016687). (End)
a(n) = A014494(n)/2 = A274757(n)/3 = A266883(n) - 1. - Hugo Pfoertner, Dec 31 2024

A053646 Distance to nearest power of 2.

Original entry on oeis.org

0, 0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 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, 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, 25
Offset: 1

Author

Henry Bottomley, Mar 22 2000

Keywords

Comments

Sum_{j=1..2^(k+1)} a(j) = A002450(k) = (4^k - 1)/3. - Klaus Brockhaus, Mar 17 2003

Examples

			a(10)=2 since 8 is closest power of 2 to 10 and |8-10| = 2.
		

Programs

  • Maple
    a:= n-> (h-> min(n-h, 2*h-n))(2^ilog2(n)):
    seq(a(n), n=1..100);  # Alois P. Heinz, Mar 28 2021
  • Mathematica
    np2[n_]:=Module[{min=Floor[Log[2,n]],max},max=min+1;If[2^max-nHarvey P. Dale, Feb 21 2012 *)
  • PARI
    a(n)=vecmin(vector(n,i,abs(n-2^(i-1))))
    
  • PARI
    for(n=1,89,p=2^floor(0.1^25+log(n)/log(2)); print1(min(n-p,2*p-n),","))
    
  • PARI
    a(n) = my (p=#binary(n)); return (min(n-2^(p-1), 2^p-n)) \\ Rémy Sigrist, Mar 24 2018
    
  • Python
    def A053646(n): return min(n-(m := 2**(len(bin(n))-3)),2*m-n) # Chai Wah Wu, Mar 08 2022

Formula

a(2^k+i) = i for 1 <= i <= 2^(k-1); a(3*2^k+i) = 2^k-i for 1 <= i <= 2^k; (Sum_{k=1..n} a(k))/n^2 is bounded. - Benoit Cloitre, Aug 17 2002
a(n) = min(n-2^floor(log(n)/log(2)), 2*2^floor(log(n)/log(2))-n). - Klaus Brockhaus, Mar 08 2003
From Peter Bala, Aug 04 2022: (Start)
a(n) = a( 1 + floor((n-1)/2) ) + a( ceiling((n-1)/2) ).
a(2*n) = 2*a(n); a(2*n+1) = a(n) + a(n+1) for n >= 2. Cf. A006165. (End)
a(n) = 2*A006165(n) - n for n >= 2. - Peter Bala, Sep 25 2022

A053187 Square nearest to n.

Original entry on oeis.org

0, 1, 1, 4, 4, 4, 4, 9, 9, 9, 9, 9, 9, 16, 16, 16, 16, 16, 16, 16, 16, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
Offset: 0

Author

Henry Bottomley, Mar 01 2000

Keywords

Comments

Apart from 0, k^2 appears 2k times from a(k^2-k+1) through to a(k^2+k) inclusive.

Examples

			a(7) = 9 since 7 is closer to 9 than to 4.
G.f. = x + x^2 + 4*x^3 + 4*x^4 + 4*x^5 + 4*x^6 + 9*x^7 + 9*x^8 + 9*x^9 + ...
		

Crossrefs

Cf. A061023, A201053 (nearest cube), A000290, A000194.

Programs

  • Haskell
    a053187 n = a053187_list !! n
    a053187_list = 0 : concatMap (\x -> replicate (2*x) (x ^ 2)) [1..]
    -- Reinhard Zumkeller, Nov 28 2011
    
  • Maple
    seq(ceil((-1+sqrt(4*n+1))/2)^2, n=0..20); # Robert Israel, Jan 05 2015
  • Mathematica
    nearestSq[n_] := Block[{a = Floor@ Sqrt@ n}, If[a^2 + a + 1/2 > n, a^2, a^2 + 2 a + 1]]; Array[ nearestSq, 75, 0] (* Robert G. Wilson v, Aug 01 2014 *)
  • Python
    from math import isqrt
    def A053187(n): return ((m:=isqrt(n))+int(n>m*(m+1)))**2 # Chai Wah Wu, Jun 06 2025

Formula

a(n) = ceiling((-1 + sqrt(4*n+1))/2)^2. - Robert Israel, Aug 01 2014
G.f.: (1/(1-x))*Sum_{n>=0} (2*n+1)*x^(n^2+n+1). - Robert Israel, Aug 01 2014. This is related to the Jacobi theta-function theta'_1(q), see A002483 and A245552.
G.f.: x / (1-x) * Sum_{k>0} (2*k - 1) * x^(k^2 - k). - Michael Somos, Jan 05 2015
a(n) = floor(sqrt(n)+1/2)^2. - Mikael Aaltonen, Jan 17 2015
Sum_{n>=1} 1/a(n)^2 = 2*zeta(3). - Amiram Eldar, Aug 15 2022
a(n) = A000194(n)^2. - Chai Wah Wu, Jun 06 2025

Extensions

Title improved by Jon E. Schoenfield, Jun 09 2019

A053615 Pyramidal sequence: distance to nearest product of two consecutive integers (promic or heteromecic numbers).

Original entry on oeis.org

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

Author

Henry Bottomley, Mar 20 2000

Keywords

Comments

a(A002378(n)) = 0; a(n^2) = n.
Table A049581 T(n,k) = |n-k| read by sides of squares from T(1,n) to T(n,n), then from T(n,n) to T(n,1). - Boris Putievskiy, Jan 29 2013

Examples

			a(10) = |10 - 3*4| = 2.
From _Boris Putievskiy_, Jan 29 2013: (Start)
The start of the sequence as table:
  0, 1, 2, 3, 4, 5, 6, 7, ...
  1, 0, 1, 2, 3, 4, 5, 6, ...
  2, 1, 0, 1, 2, 3, 4, 5, ...
  3, 2, 1, 0, 1, 2, 3, 4, ...
  4, 3, 2, 1, 0, 1, 2, 3, ...
  5, 4, 3, 2, 1, 0, 1, 2, ...
  6, 5, 4, 3, 2, 1, 0, 1, ...
  ...
The start of the sequence as triangle array read by rows:
  0;
  1, 0, 1;
  2, 1, 0, 1, 2;
  3, 2, 1, 0, 1, 2, 3;
  4, 3, 2, 1, 0, 1, 2, 3, 4;
  5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5;
  6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6;
  7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7;
  ...
Row number r contains 2*r-1 numbers: r-1, r-2, ..., 0, 1, 2, ..., r-1. (End)
		

Programs

  • Maple
    A053615 := proc(n)
        A004738(n+1)-1 ; # reuses code of A004738
    end proc:
    seq(A053615(n),n=0..30) ; # R. J. Mathar, Feb 14 2019
  • Mathematica
    a[0] = 0; a[n_] := Floor[Sqrt[n]] - a[n - Floor[Sqrt[n]]]; Table[a[n], {n, 0, 103}] (* Jean-François Alcover, Dec 16 2011, after Benoit Cloitre *)
    Join[{0},Module[{nn=150,ptci},ptci=Times@@@Partition[Range[nn/2+1],2,1];Table[Abs[n-Nearest[ptci,n]],{n,nn}][[All,1]]]] (* Harvey P. Dale, Aug 29 2020 *)
  • PARI
    a(n)=sqrtint(n)-a(n-sqrtint(n))
    
  • PARI
    apply( {A053615(n)=(t=sqrt(n)\/1)-abs(t^2-n)}, [0..99]) \\ M. F. Hasler, Feb 01 2025
    
  • Python
    A053615 = lambda n: (t := round(n**.5)) - abs(t**2 - n) # M. F. Hasler, Feb 01 2025
    
  • Python
    from math import isqrt
    def A053615(n): return abs((t:=isqrt(n))*(t+1)-n) # Chai Wah Wu, Mar 01 2025

Formula

a(n) = A004738(n+1) - 1.
Let u(1)=1, u(n) = n - u(n-sqrtint(n)) (cf. A037458); then a(0)=0 and for n > 0 a(n) = 2*u(n) - n. - Benoit Cloitre, Dec 22 2002
a(0)=0 then a(n) = floor(sqrt(n)) - a(n - floor(sqrt(n))). - Benoit Cloitre, May 03 2004
a(n) = |A196199(n)|. a(n) = |n - t^2 - t|, where t = floor(sqrt(n)). - Boris Putievskiy, Jan 29 2013 [corrected by Ridouane Oudra, May 11 2019]
a(n) = A000194(n) - A053188(n) = t - |t^2 - n|, where t = floor(sqrt(n)+1/2). - Ridouane Oudra, May 11 2019

A053616 Pyramidal sequence: distance to nearest triangular number.

Original entry on oeis.org

0, 0, 1, 0, 1, 1, 0, 1, 2, 1, 0, 1, 2, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 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, 6, 5, 4, 3, 2, 1
Offset: 0

Author

Henry Bottomley, Mar 20 2000

Keywords

Comments

From Wolfdieter Lang, Oct 24 2020: (Start)
If this sequence is written with offset 1 as a number triangle T(n, k), with n the length of row n, for n >= 1, then row n gives the primitive period of the periodic sequence {k (mod* n)}_{k>=0}, where k (mod* n) = k (mod n) if k <= floor(n/2) and otherwise it is -k (mod n). Such a modified modular relation mod* n has been used by Brändli and Beyne, but for integers relative prime to n.
These periodic sequences are given in A000007, A000035, A011655, A007877, |A117444|, A260686, A279316, for n = 1, 2, ..., 7. For n = 10 A271751, n = 12 A271832, n = 14 A279313. (End)

Examples

			a(12) = |12 - 10| = 2 since 10 is the nearest triangular number to 12.
From _M. F. Hasler_, Dec 06 2019: (Start)
Ignoring a(0) = 0, the sequence can be written as triangle indexed by m >= k >= 1, in which case the terms are (m - |k - |m-k||)/2, as follows:
   0,      (Row 0: ignore)
   0,      (Row m=1, k=1: For k=m, m - |k - |m-k|| = m - |m - 0| = 0.)
   1, 0,        (Row m=2: for k=1, |m-k| = 1, k-|m-k| = 0, m-0 = 2, (...)/2 = 1.)
   1, 1, 0,
   1, 2, 1, 0,    (Row m=4: for k=2, we have twice the value of (m=2, k=1) => 2.)
   1, 2, 2, 1, 0,
   (...)
This is related to the non-associative operation A049581(x,y) = |x - y| =: x @ y. Specifically, @ is commutative and any x is its own inverse, so non-associativity of @ can be measured through the commutator ((x @ y) @ y) @ x which equals twice the element indexed {m,k} = {x,y} in the above triangle.
(End)
		

Crossrefs

a(n) = abs(A305258(n)).

Programs

  • Mathematica
    a[n_] := (k =.; k = Reduce[k > 0 && k*(k+1)/2 == n, Reals][[2]] // Floor; Min[(k+1)*(k+2)/2 - n, n - k*(k+1)/2]); Table[a[n], {n, 0, 104}] (* Jean-François Alcover, Jan 08 2013 *)
    Module[{trms=120,t},t=Accumulate[Range[Ceiling[(Sqrt[8*trms+1]-1)/2]]]; Join[{0},Flatten[Table[Abs[Nearest[t,n][[1]]-n],{n,trms}]]]] (* Harvey P. Dale, Nov 08 2013 *)
  • PARI
    print1(x=0, ", ");for(stride=1,13,x+=stride;y=x+stride+1;for(k=x,y-1,print1(min(k-x,y-k), ", "))) \\ Hugo Pfoertner, Jun 02 2018
    
  • PARI
    apply( {a(n)=if(n,-abs(n*2-(n=sqrtint(8*n-7)\/2)^2)+n)\2}, [0..40]) \\ same as (i - |j - |i-j||)/2 with i=sqrtint(8*n-7)\/2, j=n-i(i-1)/2. - M. F. Hasler, Dec 06 2019
    
  • Python
    from math import isqrt
    def A053616(n): return abs((m:=isqrt(k:=n<<1))*(m+1)-k)>>1 # Chai Wah Wu, Jul 15 2022

Formula

a(n) = (x - |y - |x-y||)/2, when (x,y) is the n-th element in the triangle x >= y >= 1. - M. F. Hasler, Dec 06 2019
a(n) = (1/2)*abs(t^2 + t - 2*n), where t = floor(sqrt(2*n)) = A172471. - Ridouane Oudra, Dec 15 2021
From Ctibor O. Zizka, Nov 12 2024: (Start)
For s >= 1, t from [0, s] :
a(2*s^2 + t) = s - t.
a(2*s^2 - t) = s - t.
a(2*s^2 + 2*s - t) = s - t.
a(2*s^2 + 2*s + 1 + t) = s - t. (End)

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

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

A080883 Distance of n to next square.

Original entry on oeis.org

1, 3, 2, 1, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 19, 18, 17, 16, 15, 14, 13
Offset: 0

Author

Ralf Stephan, Mar 29 2003

Keywords

Comments

The following sequences all have the same parity: A004737, A006590, A027052, A071028, A071797, A078358, A078446, A080883. - Jeremy Gardiner, Dec 30 2006

Crossrefs

Cf. A075555.
Cf. A066635, A053188. - R. J. Mathar, Aug 08 2009

Programs

  • GAP
    List([0..90], n-> Int(1+RootInt(n))^2 -n); # G. C. Greubel, Nov 07 2019
  • Magma
    [Floor(1+Sqrt(n))^2 -n: n in [0..90]]; // G. C. Greubel, Nov 07 2019
    
  • Maple
    A080883 := proc(n) (floor(sqrt(n)+1))^2 -n ; end: seq( A080883(n),n=0..40) ; # R. J. Mathar, Aug 08 2009
  • Mathematica
    Table[Floor[1+Sqrt[n]]^2 -n, {n,0,90}] (* G. C. Greubel, Nov 07 2019 *)
  • PARI
    a(n) = (sqrtint(n)+1)^2-n; \\ Michel Marcus, May 22 2024
    
  • Sage
    [floor(1+sqrt(n))^2 -n for n in (0..90)] # G. C. Greubel, Nov 07 2019
    

Formula

a(n) = floor( sqrt(n)+1 )^2 - n.

A351830 Distance from the n-th square pyramidal number (sum of the first n positive squares) to the nearest square.

Original entry on oeis.org

0, 0, 1, 2, 5, 6, 9, 4, 8, 4, 15, 22, 25, 22, 9, 15, 25, 21, 7, 30, 46, 53, 49, 32, 0, 49, 40, 41, 30, 91, 46, 12, 9, 15, 4, 26, 77, 114, 25, 91, 61, 105, 15, 122, 129, 66, 22, 1, 1, 24, 76, 157, 170, 37, 131, 141, 91, 139, 165, 15, 174, 247, 150, 80, 39, 29
Offset: 0

Author

Paolo Xausa, Feb 21 2022

Keywords

Comments

As noted by Conway and Sloane (1999), the only zero terms appear at n = 0, n = 1 and n = 24, and the n = 24 case allows for the Lorentzian construction of the Leech lattice through the A351831 vector.
The zero terms are equivalently the subject of the "pile of cannonballs" problem posed by Lucas and solved by Watson. - Peter Munn, Aug 03 2023

Examples

			a(4) = 5 because the sum of the first 4 positive squares is 1 + 4 + 9 + 16 = 30, the nearest square is 25 and 30 - 25 = 5. - _Paolo Xausa_, Jul 05 2022
		

References

  • W. Ljunggren, New solution of a problem proposed by E. Lucas, Norsk Mat. Tidsskr. 34 (1952), pp 65-72.
  • David Wells, The Penguin Dictionary of Curious and Interesting Numbers, Penguin Books, 1987, entry 24, p 101.

Programs

  • Mathematica
    nterms=66;Array[Abs[(s=#(#+1)(2#+1)/6)-Round[Sqrt[s]]^2]&,nterms,0]
  • Python
    from math import isqrt
    def a(n):
        t = n*(n+1)*(2*n+1)//6
        r = isqrt(t)
        return min(t - r**2, (r+1)**2 - t)
    print([a(n) for n in range(66)]) # Michael S. Branicky, Feb 21 2022

Formula

From Paolo Xausa, Jul 05 2022: (Start)
a(n) = A053188(A000330(n)).
a(n) = abs(A000330(n) - A353295(n)). (End)

Extensions

Name edited by Peter Munn, Aug 04 2023

A038760 a(n) = n - floor(sqrt(n)) * ceiling(sqrt(n)).

Original entry on oeis.org

0, 0, 0, 1, 0, -1, 0, 1, 2, 0, -2, -1, 0, 1, 2, 3, 0, -3, -2, -1, 0, 1, 2, 3, 4, 0, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 0, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 0, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 0, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, -8, -7, -6, -5, -4
Offset: 0

Author

Henry Bottomley, May 03 2000

Keywords

Examples

			Sqrt(31) is between 5 and 6, and 31 - 6*5 = 1, so a(31)=1.
		

Crossrefs

Cf. A053188.

Programs

  • Maple
    a:= n-> n -(x-> floor(x)*ceil(x))(sqrt(n)):
    seq(a(n), n=0..100);  # Alois P. Heinz, Jan 03 2015
  • Mathematica
    f[n_]:=n-Floor[Sqrt[n]]*Ceiling[Sqrt[n]];Table[f[n],{n,0,5!}] (* Vladimir Joseph Stephan Orlovsky, Mar 29 2010 *)
  • PARI
    a(n)=if(issquare(n),0,my(s=sqrtint(n));n-s^2-s) \\ Charles R Greathouse IV, Feb 07 2013
    
  • Python
    from math import isqrt
    def A038760(n): return m-k if (m:=n-(k:=isqrt(n))**2) else 0 # Chai Wah Wu, Jul 28 2022

Formula

a(n) = n - A000196(n)*A003059(n) = n - A038759(n).

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

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.
		

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
Showing 1-10 of 19 results. Next