

A003285


Period of continued fraction for square root of n (or 0 if n is a square).
(Formerly M0018)


100



0, 1, 2, 0, 1, 2, 4, 2, 0, 1, 2, 2, 5, 4, 2, 0, 1, 2, 6, 2, 6, 6, 4, 2, 0, 1, 2, 4, 5, 2, 8, 4, 4, 4, 2, 0, 1, 2, 2, 2, 3, 2, 10, 8, 6, 12, 4, 2, 0, 1, 2, 6, 5, 6, 4, 2, 6, 7, 6, 4, 11, 4, 2, 0, 1, 2, 10, 2, 8, 6, 8, 2, 7, 5, 4, 12, 6, 4, 4, 2, 0, 1, 2, 2, 5, 10, 2, 6, 5, 2, 8, 8, 10, 16, 4, 4, 11, 4, 2, 0, 1, 2, 12
(list;
graph;
refs;
listen;
history;
text;
internal format)



OFFSET

1,3


COMMENTS

Any string of five consecutive terms m^2  2 through m^2 + 2 for m > 2 in the sequence has the corresponding periods 4,2,0,1,2.  Lekraj Beedassy, Jul 17 2001
For m > 1, a(m^2+m) = 2 and the continued fraction is m, 2, 2*m, 2, 2*m, 2, 2*m, ...  Arran Fernandez, Aug 14 2011
Apparently the generating function of the sequence for the denominators of continued fraction convergents to sqrt(n) is always rational and of form p(x)/[1  C*x^m + (1)^m * x^(2m)], or equivalently, the denominators satisfy the linear recurrence b(n+2m) = C*b(n+m)  (1)^m * b(n), where a(n) is equal to m for each nonsquare n, or 0. See A006702 for the conjecture regarding C. The same conjectures apply to the sequences of the numerators of continued fraction convergents to sqrt(n).  Ralf Stephan, Dec 12 2013
If a(n)=1, n is of form k^2+1 (A069987). See A013642 for a(n)=2, A013643 for a(n)=3, A013644 for a(n)=4, A010337 for a(n)=5, A020347 for a(n)=6, A010338 for a(n)=7, A020348 for a(n)=8, A010339 for a(n)=9, and furthermore A020349A020439.  Ralf Stephan, Dec 12 2013


REFERENCES

A. Brousseau, Number Theory Tables. Fibonacci Association, San Jose, CA, 1973, p. 197.
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).


LINKS



MAPLE

f:= n > if issqr(n) then 0
else nops(numtheory:cfrac(sqrt(n), 'periodic', 'quotients')[2]) fi:


MATHEMATICA

a[n_] := ContinuedFraction[Sqrt[n]] // If[Length[ # ] == 1, 0, Length[Last[ # ]]]&
pcf[n_]:=Module[{s=Sqrt[n]}, If[IntegerQ[s], 0, Length[ContinuedFraction[s][[2]]]]]; Array[pcf, 110] (* Harvey P. Dale, Jul 15 2017 *)


PROG

(PARI) a(n)=if(issquare(n), return(0)); my(s=sqrt(n), x=s, f=floor(s), P=[0], Q=[1], k); while(1, k=#P; P=concat(P, f*Q[k]P[k]); Q=concat(Q, (nP[k+1]^2)/Q[k]); k++; for(i=1, k1, if(P[i]==P[k]&&Q[i]==Q[k], return(ki))); x=(P[k]+s)/Q[k]; f=floor(x)) \\ Charles R Greathouse IV, Jul 31 2011
(PARI) isok(n, p) = {localprec(p); my(cf = contfrac(sqrt(n))); setsearch(Set(cf), 2*cf[1]); }
a(n) = {if (issquare(n), 0, my(p=100); while (! isok(n, p), p+=100); localprec(p); my(cf = contfrac(sqrt(n))); for (k=2, #cf, if (cf[k] == 2*cf[1], return (k1))); ); } \\ Michel Marcus, Jul 07 2021
(Python)
from sympy.ntheory.continued_fraction import continued_fraction_periodic
def a(n):
cfp = continued_fraction_periodic(0, 1, d=n)
return 0 if len(cfp) == 1 else len(cfp[1])


CROSSREFS



KEYWORD

nonn,nice


AUTHOR



STATUS

approved



