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.

Showing 1-1 of 1 results.

A160520 a(n) is the number of distinct values in the periodic part of the continued fraction of the square root of n-th nonsquare positive integer.

Original entry on oeis.org

1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 3, 2, 1, 2, 4, 2, 3, 4, 3, 2, 1, 2, 3, 3, 2, 4, 2, 3, 3, 2, 1, 2, 2, 2, 2, 2, 4, 3, 3, 5, 3, 2, 1, 2, 4, 3, 4, 2, 2, 3, 2, 4, 3, 5, 3, 2, 1, 2, 5, 2, 4, 3, 4, 2, 3, 2, 2, 5, 4, 3, 3, 2, 1, 2, 2
Offset: 1

Views

Author

Dremov Dmitry (dremovd(AT)gmail.com), May 16 2009

Keywords

Examples

			The 10th nonsquare positive integer is 13; sqrt(13) = cf[3;(1,1,1,1,6)], which has period 5, and 2 distinct values in its periodic part.
		

Crossrefs

Programs

  • Mathematica
    Length@Union@Last@ContinuedFraction@Sqrt@#&/@Select[Range@100,!IntegerQ@Sqrt@#&] (* Giorgos Kalogeropoulos, May 05 2022 *)
  • Python
    import math
    def findperiod( d ) :
        if len(d) == 0 :
            return 0
        for p in range( 1, len(d) - 1 ) :
            isPeriod = True
            for i in range(0, p) :
                for j in range(i + p, len(d), p ) :
                    if not d[i] == d[j] :
                        isPeriod = False
                        break
                if not isPeriod :
                    break
            if isPeriod :
                return len( set( d[:p] ) )
        return -1
    def nextv( a, b, n, less = True ) :
        # print a, b, a[1]*a[1], n * a[0] * a[0]
        d = -1
        while (a[1]*a[1] < n * a[0] * a[0]) == less :
            d += 1
            a = ( a[0] + b[0], a[1] + b[1] )
        a = ( a[0] - b[0], a[1] - b[1] )
        return d, a, b
    def generated( n ) :
        maxperiod = 100
        s = int( math.sqrt( n ) )
        if s * s == n :
            return []
        a = (1, 0)
        b = (0, 1)
        ds = []
        for i in range( maxperiod ):
            d, b, a = nextv( a, b, n )
            ds.append( d )
            d, b, a = nextv( a, b, n, less = False )
            ds.append( d )
        return ds[1:]
    maxn = 1000
    ns = [x for x in range( maxn ) if not int( math.sqrt( x ) ) ** 2 == x ]
    v = list(map( findperiod, map( generated, ns ) ))
    if v.count( -1 ) == 0 :
        print(v)
    
  • Python
    from math import isqrt
    from sympy.ntheory.continued_fraction import continued_fraction_periodic
    def A160520(n): return len(set(continued_fraction_periodic(0,1,n+(k:=isqrt(n))+int(n>=k*(k+1)+1))[-1])) # Chai Wah Wu, Jul 20 2024
Showing 1-1 of 1 results.