A003285 Period of continued fraction for square root of n (or 0 if n is a square).
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
Offset: 1
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
- Ray Chandler, Table of n, a(n) for n = 1..10000 (first 5000 terms from T. D. Noe)
- Marius Beceanu, Period of the Continued Fraction of sqrt(n), (Feb 05 2003)
- Leon Bernstein, Fundamental units and cycles in the period of real quadratic number fields, I. Pacific J. Math 63 (1976): 37-61.
- Ron Knott, All square-root continued fractions eventually repeat
- R. Luczak, Patterns in the period lengths of simple periodic continued fractional representations of square roots of integers near perfect squares, QED: Chicago's Youth Math Research Symposium (April 2013).
- R. Mestrovic, Euclid's theorem on the infinitude of primes: a historical survey of its proofs (300 BC--2012) and another new proof, arXiv preprint arXiv:1202.3670 [math.HO], 2012-2018. - From _N. J. A. Sloane_, Jun 13 2012
- Justin T. Miller, Families of Continued Fractions, translated (2000) from a document of Nikos Drakos, Computer Based Learning Unit, University of Leeds.
- C. D. Patterson and H. C. Williams, Some Periodic Continued Fractions with Long Periods, Mathematics of Computation, Vol. 44 (1985), No. 170, pp. 523-532.
- A. M. Rockett and P. Szuesz, On the lengths of the periods of the continued fractions of square-roots of integers, Forum Mathematicum, 2 (1990), 119-123.
- R. G. Stanton, C. Sudler, Jr. and H. C. Williams, An Upper Bound for the Period of the Simple Continued Fraction for Sqrt(D), Pacific Journal of Math., Vol. 67 (1976), No. 2, pp. 525-536.
- Hanna Uscka-Wehlou, Continued Fractions and Digital Lines with Irrational Slopes, in Discrete Geometry for Computer Imagery, Lecture Notes in Computer Science, Volume 4992/2008, Springer-Verlag.
- A. J. van der Poorten, Fractional Parts of the Period of the Continued Fraction Expansion of Quadratic Integers [Refined and revised text of a talk given at the 2nd Conference of the Canadian Number Theory Association, Vancouver, 1989]
- A. J. van der Poorten, An introduction to continued fractions, Unpublished.
- A. J. van der Poorten, An introduction to continued fractions, Unpublished [Cached copy]
- H. C. Williams, A Numerical Investigation Into the Length of the Period of the Continued Fraction Expansion of Sqrt(D), Mathematics of Computation, Vol. 36 (1981), No. 154, pp. 593-601.
Programs
-
Maple
f:= n -> if issqr(n) then 0 else nops(numtheory:-cfrac(sqrt(n),'periodic','quotients')[2]) fi: map(f, [$1..100]); # Robert Israel, Sep 02 2015
-
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 *)
-
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
-
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 (k-1))););} \\ 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]) print([a(n) for n in range(1, 104)]) # Michael S. Branicky, Aug 22 2021
Comments