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.

A066635 Distance from n to closest square different from n.

This page as a plain text file.
%I A066635 #15 Dec 20 2024 13:49:58
%S A066635 1,1,1,3,1,2,2,1,5,1,2,3,3,2,1,7,1,2,3,4,4,3,2,1,9,1,2,3,4,5,5,4,3,2,
%T A066635 1,11,1,2,3,4,5,6,6,5,4,3,2,1,13,1,2,3,4,5,6,7,7,6,5,4,3,2,1,15,1,2,3,
%U A066635 4,5,6,7,8,8,7,6,5,4,3,2,1,17,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1,19,1,2
%N A066635 Distance from n to closest square different from n.
%C A066635 The oscillatory nature of the sequence with increasing amplitude is quite evident.
%H A066635 Robert Israel, <a href="/A066635/b066635.txt">Table of n, a(n) for n = 1..10000</a>
%F A066635 a(n) = Min {n - floor(sqrt(n))^2, (floor(sqrt(n))+1)^2 - n} if n is not a square. a(n) = 2*sqrt(n) - 1 if n is a square.
%F A066635 G.f.: -x^2/(1-x)^2 + Sum_{m>=1} x^(m^2)*(2m - x^m*(x+x^2)/(1-x)^2 -(1-4*x+x^2)/(1-x)^2). - _Robert Israel_, Nov 07 2017
%e A066635 a(11) = 2 as 11 is closer to 9 than to 16 and 11 - 9 = 2.
%p A066635 N:= 10: # to get a(1)..a((N+1)^2-1)
%p A066635 seq(op([m^2-(m-1)^2, seq(i-m^2,i=m^2+1..m^2+m),seq((m+1)^2-i,i=m^2+m+1..(m+1)^2-1)]),m=1..N); # _Robert Israel_, Nov 07 2017
%t A066635 dncls[n_]:=If[IntegerQ[Sqrt[n]],Min[n-(Sqrt[n]-1)^2,(Sqrt[n]+1)^2-n],Min[n-Floor[Sqrt[n]]^2,Ceiling[Sqrt[n]]^2-n]]; Array[dncls,120] (* _Harvey P. Dale_, Dec 20 2024 *)
%K A066635 easy,nonn,look
%O A066635 1,4
%A A066635 _Amarnath Murthy_, Dec 29 2001
%E A066635 More terms from Larry Reeves (larryr(AT)acm.org), Apr 03 2002