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.

A256243 Smallest positive integer m such that n + 2m is a square.

Original entry on oeis.org

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

Views

Author

Zak Seidov, Mar 20 2015

Keywords

Examples

			1 + 2*4 = 9 = 3^2 so a(1) = 4.
2 + 2*1 = 4 = 2^2, so a(2) = 1.
3 + 2*3 = 9 = 3^2, so a(3) = 3.
		

Crossrefs

Programs

  • Mathematica
    Table[m = 1; While[! IntegerQ[Sqrt[n + 2*m]], m++]; m, {n, 100}] (* Michael De Vlieger, Mar 20 2015 *)
  • PARI
    a(n)=m=1;while(!issquare(n+2*m),m++);m
    vector(100,n,a(n)) \\ Derek Orr, Mar 22 2015
    
  • PARI
    a(n)=my(s=sqrtint(n)); (if((s-n)%2,s+1,s+2)^2-n)/2 \\ Charles R Greathouse IV, Mar 23 2015

Formula

1 <= a(n) <= 2*sqrt(n) + 2. - Charles R Greathouse IV, Mar 23 2015
a(n) = (1/4)*(6*floor(sqrt(n)) + 2*floor(sqrt(n))^2 + (2*floor(sqrt(n)) + 3)*(-1)^(n - floor(sqrt(n))) - 2*n + 5). - Ridouane Oudra, Oct 09 2020