Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #20 Jul 20 2024 15:33:53
%S 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,
%T 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,
%U 4,3,3,2,1,2,2
%N 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.
%e 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.
%t Length@Union@Last@ContinuedFraction@Sqrt@#&/@Select[Range@100,!IntegerQ@Sqrt@#&] (* _Giorgos Kalogeropoulos_, May 05 2022 *)
%o (Python)
%o import math
%o def findperiod( d ) :
%o if len(d) == 0 :
%o return 0
%o for p in range( 1, len(d) - 1 ) :
%o isPeriod = True
%o for i in range(0, p) :
%o for j in range(i + p, len(d), p ) :
%o if not d[i] == d[j] :
%o isPeriod = False
%o break
%o if not isPeriod :
%o break
%o if isPeriod :
%o return len( set( d[:p] ) )
%o return -1
%o def nextv( a, b, n, less = True ) :
%o # print a, b, a[1]*a[1], n * a[0] * a[0]
%o d = -1
%o while (a[1]*a[1] < n * a[0] * a[0]) == less :
%o d += 1
%o a = ( a[0] + b[0], a[1] + b[1] )
%o a = ( a[0] - b[0], a[1] - b[1] )
%o return d, a, b
%o def generated( n ) :
%o maxperiod = 100
%o s = int( math.sqrt( n ) )
%o if s * s == n :
%o return []
%o a = (1, 0)
%o b = (0, 1)
%o ds = []
%o for i in range( maxperiod ):
%o d, b, a = nextv( a, b, n )
%o ds.append( d )
%o d, b, a = nextv( a, b, n, less = False )
%o ds.append( d )
%o return ds[1:]
%o maxn = 1000
%o ns = [x for x in range( maxn ) if not int( math.sqrt( x ) ) ** 2 == x ]
%o v = list(map( findperiod, map( generated, ns ) ))
%o if v.count( -1 ) == 0 :
%o print(v)
%o (Python)
%o from math import isqrt
%o from sympy.ntheory.continued_fraction import continued_fraction_periodic
%o 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
%Y Cf. A013943, A099725.
%K nonn
%O 1,2
%A Dremov Dmitry (dremovd(AT)gmail.com), May 16 2009