login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A003285 Period of continued fraction for square root of n (or 0 if n is a square).
(Formerly M0018)
100

%I M0018 #103 Oct 29 2023 01:43:50

%S 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,

%T 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,

%U 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

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

%C 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

%C 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

%C 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

%C 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 A020349-A020439. - _Ralf Stephan_, Dec 12 2013

%D A. Brousseau, Number Theory Tables. Fibonacci Association, San Jose, CA, 1973, p. 197.

%D N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

%H Ray Chandler, <a href="/A003285/b003285.txt">Table of n, a(n) for n = 1..10000</a> (first 5000 terms from T. D. Noe)

%H Marius Beceanu, <a href="http://web.math.princeton.edu/mathlab/jr02fall/Periodicity/mariusjp.pdf">Period of the Continued Fraction of sqrt(n)</a>, (Feb 05 2003)

%H Leon Bernstein, <a href="http://scholar.google.de/scholar?cluster=3688217905613415587">Fundamental units and cycles in the period of real quadratic number fields</a>, I. Pacific J. Math 63 (1976): 37-61.

%H Ron Knott, <a href="http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfINTRO.html#sqrts">All square-root continued fractions eventually repeat</a>

%H R. Luczak, <a href="https://mathcirclesofchicago.org/wp-content/uploads/2015/08/luczak.pdf">Patterns in the period lengths of simple periodic continued fractional representations of square roots of integers near perfect squares</a>, QED: Chicago's Youth Math Research Symposium (April 2013).

%H R. Mestrovic, <a href="http://arxiv.org/abs/1202.3670">Euclid's theorem on the infinitude of primes: a historical survey of its proofs (300 BC--2012) and another new proof</a>, arXiv preprint arXiv:1202.3670 [math.HO], 2012-2018. - From _N. J. A. Sloane_, Jun 13 2012

%H Justin T. Miller, <a href="https://www.math.arizona.edu/~ura-reports/993/miller.justin/Miller.html">Families of Continued Fractions</a>, translated (2000) from a document of Nikos Drakos, Computer Based Learning Unit, University of Leeds.

%H C. D. Patterson and H. C. Williams, <a href="http://www.jstor.org/stable/2007971">Some Periodic Continued Fractions with Long Periods</a>, Mathematics of Computation, Vol. 44 (1985), No. 170, pp. 523-532.

%H A. M. Rockett and P. Szuesz, <a href="http://dx.doi.org/10.1515/form.1990.2.119">On the lengths of the periods of the continued fractions of square-roots of integers</a>, Forum Mathematicum, 2 (1990), 119-123.

%H R. G. Stanton, C. Sudler, Jr. and H. C. Williams, <a href="http://projecteuclid.org/euclid.pjm/1102817507">An Upper Bound for the Period of the Simple Continued Fraction for Sqrt(D)</a>, Pacific Journal of Math., Vol. 67 (1976), No. 2, pp. 525-536.

%H Hanna Uscka-Wehlou, <a href="http://scholar.google.de/scholar?cluster=8548357010461218230">Continued Fractions and Digital Lines with Irrational Slopes</a>, in Discrete Geometry for Computer Imagery, Lecture Notes in Computer Science, Volume 4992/2008, Springer-Verlag.

%H A. J. van der Poorten, <a href="https://pdfs.semanticscholar.org/c50f/609dc9078d6873ece1002aee061c4e5eab04.pdf">Fractional Parts of the Period of the Continued Fraction Expansion of Quadratic Integers</a> [Refined and revised text of a talk given at the 2nd Conference of the Canadian Number Theory Association, Vancouver, 1989]

%H A. J. van der Poorten, <a href="https://web.archive.org/web/*/http://www-centre.mpce.mq.edu.au/alfpapers/a075.pdf">An introduction to continued fractions</a>, Unpublished.

%H A. J. van der Poorten, <a href="/A007400/a007400_4.pdf">An introduction to continued fractions</a>, Unpublished [Cached copy]

%H H. C. Williams, <a href="http://www.jstor.org/stable/2007664">A Numerical Investigation Into the Length of the Period of the Continued Fraction Expansion of Sqrt(D)</a>, Mathematics of Computation, Vol. 36 (1981), No. 154, pp. 593-601.

%p f:= n -> if issqr(n) then 0

%p else nops(numtheory:-cfrac(sqrt(n),'periodic','quotients')[2]) fi:

%p map(f, [$1..100]); # _Robert Israel_, Sep 02 2015

%t a[n_] := ContinuedFraction[Sqrt[n]] // If[Length[ # ] == 1, 0, Length[Last[ # ]]]&

%t pcf[n_]:=Module[{s=Sqrt[n]},If[IntegerQ[s],0,Length[ContinuedFraction[s][[2]]]]]; Array[pcf,110] (* _Harvey P. Dale_, Jul 15 2017 *)

%o (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,(n-P[k+1]^2)/Q[k]);k++;for(i=1,k-1,if(P[i]==P[k]&&Q[i]==Q[k],return(k-i)));x=(P[k]+s)/Q[k];f=floor(x)) \\ _Charles R Greathouse IV_, Jul 31 2011

%o (PARI) isok(n, p) = {localprec(p); my(cf = contfrac(sqrt(n))); setsearch(Set(cf), 2*cf[1]);}

%o 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 (k-1))););} \\ _Michel Marcus_, Jul 07 2021

%o (Python)

%o from sympy.ntheory.continued_fraction import continued_fraction_periodic

%o def a(n):

%o cfp = continued_fraction_periodic(0, 1, d=n)

%o return 0 if len(cfp) == 1 else len(cfp[1])

%o print([a(n) for n in range(1, 104)]) # _Michael S. Branicky_, Aug 22 2021

%Y Cf. A035015, A013943, A054269, A061490, A065938, A067280, A097853.

%K nonn,nice

%O 1,3

%A _N. J. A. Sloane_

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 18 22:18 EDT 2024. Contains 371782 sequences. (Running on oeis4.)